Refactor
Use QWindow pointer on all platforms. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
4c65cba578
commit
137019f7e6
31
README.md
31
README.md
|
@ -52,13 +52,10 @@ If you are using part of or all the code from this repository in your own projec
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
QWidget widget;
|
||||
// Qt's internal function. Make sure it's a top level window.
|
||||
widget.createWinId();
|
||||
// Do this before the widget is shown.
|
||||
#ifdef Q_OS_WIN
|
||||
const auto id = reinterpret_cast<FramelessWindowsManager::WindowId>(widget.winId());
|
||||
#else
|
||||
const auto id = static_cast<FramelessWindowsManager::WindowId>(&widget);
|
||||
#endif
|
||||
FramelessWindowsManager::addWindow(id);
|
||||
FramelessWindowsManager::addWindow(widget.windowHandle());
|
||||
widget.show();
|
||||
}
|
||||
```
|
||||
|
@ -70,34 +67,32 @@ Please refer to [the QWidget example](/examples/QWidget/main.cpp) for more detai
|
|||
```cpp
|
||||
// Only **TOP LEVEL** QWidgets and QWindows are supported.
|
||||
QMainWindow *mainWindow = new QMainWindow;
|
||||
#ifdef Q_OS_WIN
|
||||
const auto id = reinterpret_cast<FramelessWindowsManager::WindowId>(mainWindow->winId());
|
||||
#else
|
||||
const auto id = static_cast<FramelessWindowsManager::WindowId>(mainWindow);
|
||||
#endif
|
||||
// Qt's internal function. Make sure it's a top level window.
|
||||
mainWindow->createWinId();
|
||||
const QWindow *win = mainWindow->windowHandle();
|
||||
// Disable resizing of the given window. Resizing is enabled by default.
|
||||
FramelessWindowsManager::setResizable(id, false);
|
||||
FramelessWindowsManager::setResizable(win, false);
|
||||
// All the following values should not be DPI-aware, just use the
|
||||
// original numbers, assuming the scale factor is 1.0, don't scale
|
||||
// them yourself, this code will do the scaling according to DPI
|
||||
// internally and automatically.
|
||||
// Maximum window size
|
||||
FramelessWindowsManager::setMaximumSize(id, {1280, 720});
|
||||
FramelessWindowsManager::setMaximumSize(win, {1280, 720});
|
||||
// Minimum window size
|
||||
FramelessWindowsManager::setMinimumSize(id, {800, 540});
|
||||
FramelessWindowsManager::setMinimumSize(win, {800, 540});
|
||||
// How to set ignore areas:
|
||||
// The geometry of something you already know, in window coordinates
|
||||
FramelessWindowsManager::addIgnoreArea(id, {100, 0, 30, 30});
|
||||
FramelessWindowsManager::addIgnoreArea(win, {100, 0, 30, 30});
|
||||
// The geometry of a widget, in window coordinates.
|
||||
// It won't update automatically when the geometry of that widget has
|
||||
// changed, so if you want to add a widget, which is in a layout and
|
||||
// it's geometry will possibly change, to the ignore list, try the
|
||||
// next method (addIgnoreObject) instead.
|
||||
FramelessWindowsManager::addIgnoreArea(id, pushButton_close.geometry());
|
||||
FramelessWindowsManager::addIgnoreArea(win, pushButton_close.geometry());
|
||||
// The **POINTER** of a QWidget or QQuickItem
|
||||
FramelessWindowsManager::addIgnoreObject(id, ui->pushButton_minimize);
|
||||
FramelessWindowsManager::addIgnoreObject(win, ui->pushButton_minimize);
|
||||
// Move a QWidget or QWindow to the center of its current desktop.
|
||||
FramelessWindowsManager::moveWindowToDesktopCenter(id);
|
||||
FramelessWindowsManager::moveWindowToDesktopCenter(win);
|
||||
```
|
||||
|
||||
## Supported Platforms
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
|
||||
```cpp
|
||||
QWidget widget;
|
||||
// Qt's internal function. Make sure it's a top level window.
|
||||
widget.createWinId();
|
||||
// Do this before the widget is shown.
|
||||
WinNativeEventFilter::addFramelessWindow(reinterpret_cast<void *>(widget.winId()));
|
||||
WinNativeEventFilter::addFramelessWindow(widget.windowHandle());
|
||||
widget.show();
|
||||
```
|
||||
|
||||
|
@ -41,8 +43,7 @@ Please refer to [the QWidget example](/examples/QWidget/main.cpp) for more detai
|
|||
### Ignore areas and etc
|
||||
|
||||
```cpp
|
||||
// Get the window handle (HWND) first.
|
||||
const auto handle = reinterpret_cast<void *>(widget.winId());
|
||||
const QWindow *win = widget.windowHandle();
|
||||
WinNativeEventFilter::WINDOWDATA data = {};
|
||||
// All the following values should not be DPI-aware, just use the
|
||||
// original numbers, assuming the scale factor is 1.0, don't scale
|
||||
|
@ -64,18 +65,18 @@ data.ignoreAreas.append(pushButton_close.geometry());
|
|||
// The **POINTER** of a QWidget or QQuickItem
|
||||
data.ignoreObjects.append(ui->pushButton_minimize);
|
||||
// Pass data as the second parameter
|
||||
WinNativeEventFilter::addFramelessWindow(handle, &data);
|
||||
WinNativeEventFilter::addFramelessWindow(win, &data);
|
||||
// Or
|
||||
WinNativeEventFilter::setWindowData(handle, &data);
|
||||
WinNativeEventFilter::setWindowData(win, &data);
|
||||
// Or modify the window data of a specific window directly:
|
||||
const auto data = WinNativeEventFilter::getWindowData(handle);
|
||||
const auto data = WinNativeEventFilter::getWindowData(win);
|
||||
if (data) {
|
||||
data->borderWidth = 5;
|
||||
data->borderHeight = 5;
|
||||
data->titleBarHeight = 30;
|
||||
}
|
||||
// The frameless window is resizable by default.
|
||||
WinNativeEventFilter::setWindowResizable(handle, false);
|
||||
WinNativeEventFilter::setWindowResizable(win, false);
|
||||
```
|
||||
|
||||
## Supported Platforms
|
||||
|
|
|
@ -103,18 +103,13 @@ int main(int argc, char *argv[])
|
|||
mainWindow->setWindowIcon(icon);
|
||||
mainWindow->setWindowTitle(QObject::tr("Hello, World!"));
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
const auto id = reinterpret_cast<FramelessWindowsManager::WindowId>(mainWindow->winId());
|
||||
#else
|
||||
const auto id = static_cast<FramelessWindowsManager::WindowId>(mainWindow);
|
||||
#endif
|
||||
|
||||
FramelessWindowsManager::addWindow(id);
|
||||
|
||||
FramelessWindowsManager::addIgnoreObject(id, titleBarWidget.minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(id, titleBarWidget.maximizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(id, titleBarWidget.closeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(id, appMainWindow.menubar);
|
||||
mainWindow->createWinId(); // Qt's internal function, make sure it's a top level window.
|
||||
const QWindow *win = mainWindow->windowHandle();
|
||||
FramelessWindowsManager::addWindow(win);
|
||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.maximizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(win, titleBarWidget.closeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(win, appMainWindow.menubar);
|
||||
|
||||
mainWindow->resize(800, 600);
|
||||
|
||||
|
|
|
@ -94,17 +94,12 @@ int main(int argc, char *argv[])
|
|||
widget.setLayout(mainLayout);
|
||||
widget.setWindowTitle(QObject::tr("Hello, World!"));
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
const auto id = reinterpret_cast<FramelessWindowsManager::WindowId>(widget.winId());
|
||||
#else
|
||||
const auto id = static_cast<FramelessWindowsManager::WindowId>(&widget);
|
||||
#endif
|
||||
|
||||
FramelessWindowsManager::addWindow(id);
|
||||
|
||||
FramelessWindowsManager::addIgnoreObject(id, minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(id, maximizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(id, closeButton);
|
||||
widget.createWinId(); // Qt's internal function, make sure it's a top level window.
|
||||
const QWindow *win = widget.windowHandle();
|
||||
FramelessWindowsManager::addWindow(win);
|
||||
FramelessWindowsManager::addIgnoreObject(win, minimizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(win, maximizeButton);
|
||||
FramelessWindowsManager::addIgnoreObject(win, closeButton);
|
||||
|
||||
widget.resize(800, 600);
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ const QLatin1String g_sCloseButtonImageLight(":/images/button_close_white.svg");
|
|||
|
||||
Widget::Widget(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
createWinId(); // Internal function
|
||||
createWinId(); // Qt's internal function, make sure it's a top level window.
|
||||
initializeWindow();
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ void Widget::setupUi()
|
|||
sizePolicy.setHeightForWidth(titleBarWidget->sizePolicy().hasHeightForWidth());
|
||||
titleBarWidget->setSizePolicy(sizePolicy);
|
||||
const int titleBarHeight
|
||||
= WinNativeEventFilter::getSystemMetric(rawHandle(),
|
||||
= WinNativeEventFilter::getSystemMetric(windowHandle(),
|
||||
WinNativeEventFilter::SystemMetric::TitleBarHeight);
|
||||
titleBarWidget->setMinimumSize(QSize(0, titleBarHeight));
|
||||
titleBarWidget->setMaximumSize(QSize(16777215, titleBarHeight));
|
||||
|
@ -349,11 +349,6 @@ bool Widget::isWin10OrGreater(const Win10Version subVer)
|
|||
static_cast<int>(subVer))));
|
||||
}
|
||||
|
||||
void *Widget::rawHandle() const
|
||||
{
|
||||
return reinterpret_cast<void *>(winId());
|
||||
}
|
||||
|
||||
bool Widget::eventFilter(QObject *object, QEvent *event)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
|
@ -374,7 +369,7 @@ bool Widget::eventFilter(QObject *object, QEvent *event)
|
|||
break;
|
||||
}
|
||||
case QEvent::WinIdChange:
|
||||
WinNativeEventFilter::addFramelessWindow(rawHandle());
|
||||
WinNativeEventFilter::addFramelessWindow(windowHandle());
|
||||
break;
|
||||
case QEvent::WindowActivate:
|
||||
case QEvent::WindowDeactivate:
|
||||
|
@ -401,7 +396,7 @@ bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *resul
|
|||
switch (msg->message) {
|
||||
case WM_NCRBUTTONUP: {
|
||||
if (msg->wParam == HTCAPTION) {
|
||||
if (WinNativeEventFilter::displaySystemMenu(msg->hwnd)) {
|
||||
if (WinNativeEventFilter::displaySystemMenu(windowHandle())) {
|
||||
*result = 0;
|
||||
return true;
|
||||
}
|
||||
|
@ -445,8 +440,8 @@ void Widget::paintEvent(QPaintEvent *event)
|
|||
|
||||
void Widget::updateWindow()
|
||||
{
|
||||
WinNativeEventFilter::updateFrameMargins(rawHandle());
|
||||
WinNativeEventFilter::updateWindow(rawHandle(), true, true);
|
||||
WinNativeEventFilter::updateFrameMargins(windowHandle());
|
||||
WinNativeEventFilter::updateWindow(windowHandle(), true, true);
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -503,7 +498,7 @@ void Widget::initializeOptions()
|
|||
if (m_bIsWin10OrGreater) {
|
||||
//preserveWindowFrameCB->click();
|
||||
if (m_bCanAcrylicBeEnabled) {
|
||||
forceAcrylicCB->click();
|
||||
//forceAcrylicCB->click();
|
||||
}
|
||||
}
|
||||
customizeTitleBarCB->click();
|
||||
|
@ -515,12 +510,6 @@ void Widget::initializeOptions()
|
|||
|
||||
void Widget::setupConnections()
|
||||
{
|
||||
connect(iconButton, &QPushButton::clicked, this, [this]() {
|
||||
POINT pos = {};
|
||||
GetCursorPos(&pos);
|
||||
const auto hwnd = reinterpret_cast<HWND>(rawHandle());
|
||||
SendMessageW(hwnd, WM_CONTEXTMENU, reinterpret_cast<WPARAM>(hwnd), MAKELPARAM(pos.x, pos.y));
|
||||
});
|
||||
connect(minimizeButton, &QPushButton::clicked, this, &Widget::showMinimized);
|
||||
connect(maximizeButton, &QPushButton::clicked, this, [this]() {
|
||||
if (isMaximized()) {
|
||||
|
@ -531,7 +520,7 @@ void Widget::setupConnections()
|
|||
});
|
||||
connect(closeButton, &QPushButton::clicked, this, &Widget::close);
|
||||
connect(moveCenterButton, &QPushButton::clicked, this, [this]() {
|
||||
WinNativeEventFilter::moveWindowToDesktopCenter(rawHandle());
|
||||
WinNativeEventFilter::moveWindowToDesktopCenter(windowHandle());
|
||||
});
|
||||
connect(this, &Widget::windowTitleChanged, titleLabel, &QLabel::setText);
|
||||
connect(this, &Widget::windowIconChanged, iconButton, &QPushButton::setIcon);
|
||||
|
@ -540,7 +529,7 @@ void Widget::setupConnections()
|
|||
preserveWindowFrameCB->setEnabled(enable);
|
||||
WinNativeEventFilter::updateQtFrame(windowHandle(),
|
||||
enable ? WinNativeEventFilter::getSystemMetric(
|
||||
rawHandle(),
|
||||
windowHandle(),
|
||||
WinNativeEventFilter::SystemMetric::TitleBarHeight)
|
||||
: 0);
|
||||
titleBarWidget->setVisible(enable);
|
||||
|
@ -589,7 +578,7 @@ void Widget::setupConnections()
|
|||
palette.setColor(QPalette::Window, Qt::transparent);
|
||||
}
|
||||
setPalette(palette);
|
||||
WinNativeEventFilter::setBlurEffectEnabled(rawHandle(), enable, color);
|
||||
WinNativeEventFilter::setBlurEffectEnabled(windowHandle(), enable, color);
|
||||
updateWindow();
|
||||
if (useAcrylicEffect && enable && WinNativeEventFilter::isTransparencyEffectEnabled()) {
|
||||
QMessageBox::warning(this,
|
||||
|
@ -621,7 +610,7 @@ void Widget::setupConnections()
|
|||
connect(resizableCB, &QCheckBox::stateChanged, this, [this](int state) {
|
||||
const bool enable = state == Qt::Checked;
|
||||
maximizeButton->setEnabled(enable);
|
||||
WinNativeEventFilter::setWindowResizable(rawHandle(), enable);
|
||||
WinNativeEventFilter::setWindowResizable(windowHandle(), enable);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -629,7 +618,7 @@ void Widget::initializeFramelessFunctions()
|
|||
{
|
||||
WinNativeEventFilter::WINDOWDATA data = {};
|
||||
data.ignoreObjects << iconButton << minimizeButton << maximizeButton << closeButton;
|
||||
WinNativeEventFilter::addFramelessWindow(rawHandle(), &data);
|
||||
WinNativeEventFilter::addFramelessWindow(windowHandle(), &data);
|
||||
installEventFilter(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,6 @@ public:
|
|||
explicit Widget(QWidget *parent = nullptr);
|
||||
~Widget() override = default;
|
||||
|
||||
void *rawHandle() const;
|
||||
|
||||
bool isNormaled() const;
|
||||
|
||||
bool shouldDrawBorder(const bool ignoreWindowState = false) const;
|
||||
|
|
|
@ -31,34 +31,15 @@
|
|||
#include <QOperatingSystemVersion>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
namespace {
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const char g_sPreserveWindowFrame[] = "WNEF_FORCE_PRESERVE_WINDOW_FRAME";
|
||||
const char g_sDontExtendFrame[] = "WNEF_DO_NOT_EXTEND_FRAME";
|
||||
const char g_sForceUseAcrylicEffect[] = "WNEF_FORCE_ACRYLIC_ON_WIN10";
|
||||
#endif
|
||||
|
||||
FramelessWindowsManager::WindowId getWindowId(QObject *object)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
if (!object->isWindowType()) {
|
||||
qWarning() << object << "is not a window!";
|
||||
return nullptr;
|
||||
}
|
||||
const auto window = qobject_cast<QWindow *>(object);
|
||||
if (!window) {
|
||||
qWarning() << "Failed to convert" << object << "to QWindow!";
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
return reinterpret_cast<FramelessWindowsManager::WindowId>(window->winId());
|
||||
#else
|
||||
return static_cast<FramelessWindowsManager::WindowId>(window);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
FramelessQuickHelper::FramelessQuickHelper(QQuickItem *parent) : QQuickItem(parent)
|
||||
{
|
||||
|
@ -69,56 +50,56 @@ FramelessQuickHelper::FramelessQuickHelper(QQuickItem *parent) : QQuickItem(pare
|
|||
|
||||
int FramelessQuickHelper::borderWidth() const
|
||||
{
|
||||
return FramelessWindowsManager::getBorderWidth(getWindowId(window()));
|
||||
return FramelessWindowsManager::getBorderWidth(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setBorderWidth(const int val)
|
||||
{
|
||||
FramelessWindowsManager::setBorderWidth(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setBorderWidth(window(), val);
|
||||
Q_EMIT borderWidthChanged(val);
|
||||
}
|
||||
|
||||
int FramelessQuickHelper::borderHeight() const
|
||||
{
|
||||
return FramelessWindowsManager::getBorderHeight(getWindowId(window()));
|
||||
return FramelessWindowsManager::getBorderHeight(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setBorderHeight(const int val)
|
||||
{
|
||||
FramelessWindowsManager::setBorderHeight(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setBorderHeight(window(), val);
|
||||
Q_EMIT borderHeightChanged(val);
|
||||
}
|
||||
|
||||
int FramelessQuickHelper::titleBarHeight() const
|
||||
{
|
||||
return FramelessWindowsManager::getTitleBarHeight(getWindowId(window()));
|
||||
return FramelessWindowsManager::getTitleBarHeight(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setTitleBarHeight(const int val)
|
||||
{
|
||||
FramelessWindowsManager::setTitleBarHeight(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setTitleBarHeight(window(), val);
|
||||
Q_EMIT titleBarHeightChanged(val);
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::resizable() const
|
||||
{
|
||||
return FramelessWindowsManager::getResizable(getWindowId(window()));
|
||||
return FramelessWindowsManager::getResizable(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setResizable(const bool val)
|
||||
{
|
||||
FramelessWindowsManager::setResizable(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setResizable(window(), val);
|
||||
Q_EMIT resizableChanged(val);
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::titleBarEnabled() const
|
||||
{
|
||||
return FramelessWindowsManager::getTitleBarEnabled(getWindowId(window()));
|
||||
return FramelessWindowsManager::getTitleBarEnabled(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setTitleBarEnabled(const bool val)
|
||||
{
|
||||
FramelessWindowsManager::setTitleBarEnabled(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setTitleBarEnabled(window(), val);
|
||||
Q_EMIT titleBarEnabledChanged(val);
|
||||
}
|
||||
|
||||
|
@ -155,7 +136,7 @@ bool FramelessQuickHelper::highContrastModeEnabled() const
|
|||
|
||||
bool FramelessQuickHelper::darkFrameEnabled() const
|
||||
{
|
||||
return WinNativeEventFilter::isDarkFrameEnabled(rawWindowHandle());
|
||||
return WinNativeEventFilter::isDarkFrameEnabled(window());
|
||||
}
|
||||
|
||||
bool FramelessQuickHelper::transparencyEffectEnabled() const
|
||||
|
@ -166,56 +147,56 @@ bool FramelessQuickHelper::transparencyEffectEnabled() const
|
|||
|
||||
QSize FramelessQuickHelper::minimumSize() const
|
||||
{
|
||||
return FramelessWindowsManager::getMinimumSize(getWindowId(window()));
|
||||
return FramelessWindowsManager::getMinimumSize(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setMinimumSize(const QSize &val)
|
||||
{
|
||||
FramelessWindowsManager::setMinimumSize(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setMinimumSize(window(), val);
|
||||
Q_EMIT minimumSizeChanged(val);
|
||||
}
|
||||
|
||||
QSize FramelessQuickHelper::maximumSize() const
|
||||
{
|
||||
return FramelessWindowsManager::getMaximumSize(getWindowId(window()));
|
||||
return FramelessWindowsManager::getMaximumSize(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setMaximumSize(const QSize &val)
|
||||
{
|
||||
FramelessWindowsManager::setMaximumSize(getWindowId(window()), val);
|
||||
FramelessWindowsManager::setMaximumSize(window(), val);
|
||||
Q_EMIT maximumSizeChanged(val);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::removeWindowFrame(const bool center)
|
||||
{
|
||||
FramelessWindowsManager::addWindow(getWindowId(window()), center);
|
||||
FramelessWindowsManager::addWindow(window(), center);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::moveWindowToDesktopCenter()
|
||||
{
|
||||
FramelessWindowsManager::moveWindowToDesktopCenter(getWindowId(window()));
|
||||
FramelessWindowsManager::moveWindowToDesktopCenter(window());
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::addIgnoreArea(const QRect &val)
|
||||
{
|
||||
FramelessWindowsManager::addIgnoreArea(getWindowId(window()), val);
|
||||
FramelessWindowsManager::addIgnoreArea(window(), val);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::addDraggableArea(const QRect &val)
|
||||
{
|
||||
FramelessWindowsManager::addDraggableArea(getWindowId(window()), val);
|
||||
FramelessWindowsManager::addDraggableArea(window(), val);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::addIgnoreObject(QQuickItem *val)
|
||||
{
|
||||
Q_ASSERT(val);
|
||||
FramelessWindowsManager::addIgnoreObject(getWindowId(window()), val);
|
||||
FramelessWindowsManager::addIgnoreObject(window(), val);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::addDraggableObject(QQuickItem *val)
|
||||
{
|
||||
Q_ASSERT(val);
|
||||
FramelessWindowsManager::addDraggableObject(getWindowId(window()), val);
|
||||
FramelessWindowsManager::addDraggableObject(window(), val);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -231,15 +212,6 @@ void FramelessQuickHelper::timerEvent(QTimerEvent *event)
|
|||
Q_EMIT transparencyEffectEnabledChanged(transparencyEffectEnabled());
|
||||
}
|
||||
|
||||
void *FramelessQuickHelper::rawWindowHandle() const
|
||||
{
|
||||
const QWindow *win = window();
|
||||
if (win) {
|
||||
return reinterpret_cast<void *>(win->winId());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
||||
{
|
||||
if (value) {
|
||||
|
@ -253,7 +225,7 @@ void FramelessQuickHelper::setWindowFrameVisible(const bool value)
|
|||
|
||||
void FramelessQuickHelper::displaySystemMenu(const QPointF &pos)
|
||||
{
|
||||
WinNativeEventFilter::displaySystemMenu(rawWindowHandle(), pos);
|
||||
WinNativeEventFilter::displaySystemMenu(window(), pos);
|
||||
}
|
||||
|
||||
void FramelessQuickHelper::setBlurEffectEnabled(const bool enabled,
|
||||
|
@ -265,6 +237,6 @@ void FramelessQuickHelper::setBlurEffectEnabled(const bool enabled,
|
|||
} else {
|
||||
qunsetenv(g_sForceUseAcrylicEffect);
|
||||
}
|
||||
WinNativeEventFilter::setBlurEffectEnabled(rawWindowHandle(), enabled, gradientColor);
|
||||
WinNativeEventFilter::setBlurEffectEnabled(window(), enabled, gradientColor);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -128,9 +128,6 @@ public Q_SLOTS:
|
|||
#ifdef Q_OS_WINDOWS
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event) override;
|
||||
|
||||
private:
|
||||
void *rawWindowHandle() const;
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -24,10 +24,7 @@
|
|||
|
||||
#include "framelesswindowsmanager.h"
|
||||
|
||||
#ifndef Q_OS_WINDOWS
|
||||
#include <QGuiApplication>
|
||||
#include <QWindow>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include "winnativeeventfilter.h"
|
||||
|
@ -38,12 +35,6 @@
|
|||
#ifndef Q_OS_WINDOWS
|
||||
namespace {
|
||||
|
||||
QWindow *toWindow(QObject *object)
|
||||
{
|
||||
Q_ASSERT(object);
|
||||
return object->isWindowType() ? qobject_cast<QWindow *>(object) : nullptr;
|
||||
}
|
||||
|
||||
using FLWM_CORE_DATA = struct _FLWM_CORE_DATA
|
||||
{
|
||||
FramelessHelper framelessHelper;
|
||||
|
@ -58,7 +49,7 @@ Q_GLOBAL_STATIC(FLWM_CORE_DATA, coreData)
|
|||
|
||||
FramelessWindowsManager::FramelessWindowsManager() = default;
|
||||
|
||||
void FramelessWindowsManager::addWindow(WindowId window, const bool center)
|
||||
void FramelessWindowsManager::addWindow(const QWindow *window, const bool center)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -71,7 +62,7 @@ void FramelessWindowsManager::addWindow(WindowId window, const bool center)
|
|||
}
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::moveWindowToDesktopCenter(WindowId window)
|
||||
void FramelessWindowsManager::moveWindowToDesktopCenter(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -81,7 +72,7 @@ void FramelessWindowsManager::moveWindowToDesktopCenter(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::addIgnoreArea(WindowId window, const QRect &area)
|
||||
void FramelessWindowsManager::addIgnoreArea(const QWindow *window, const QRect &area)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -94,7 +85,7 @@ void FramelessWindowsManager::addIgnoreArea(WindowId window, const QRect &area)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::addDraggableArea(WindowId window, const QRect &area)
|
||||
void FramelessWindowsManager::addDraggableArea(const QWindow *window, const QRect &area)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -107,7 +98,7 @@ void FramelessWindowsManager::addDraggableArea(WindowId window, const QRect &are
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::addIgnoreObject(WindowId window, QObject *object)
|
||||
void FramelessWindowsManager::addIgnoreObject(const QWindow *window, QObject *object)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -120,7 +111,7 @@ void FramelessWindowsManager::addIgnoreObject(WindowId window, QObject *object)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::addDraggableObject(WindowId window, QObject *object)
|
||||
void FramelessWindowsManager::addDraggableObject(const QWindow *window, QObject *object)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -133,7 +124,7 @@ void FramelessWindowsManager::addDraggableObject(WindowId window, QObject *objec
|
|||
#endif
|
||||
}
|
||||
|
||||
int FramelessWindowsManager::getBorderWidth(WindowId window)
|
||||
int FramelessWindowsManager::getBorderWidth(const QWindow *window)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -145,7 +136,7 @@ int FramelessWindowsManager::getBorderWidth(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setBorderWidth(WindowId window, const int value)
|
||||
void FramelessWindowsManager::setBorderWidth(const QWindow *window, const int value)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -159,7 +150,7 @@ void FramelessWindowsManager::setBorderWidth(WindowId window, const int value)
|
|||
#endif
|
||||
}
|
||||
|
||||
int FramelessWindowsManager::getBorderHeight(WindowId window)
|
||||
int FramelessWindowsManager::getBorderHeight(const QWindow *window)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -171,7 +162,7 @@ int FramelessWindowsManager::getBorderHeight(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setBorderHeight(WindowId window, const int value)
|
||||
void FramelessWindowsManager::setBorderHeight(const QWindow *window, const int value)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -185,7 +176,7 @@ void FramelessWindowsManager::setBorderHeight(WindowId window, const int value)
|
|||
#endif
|
||||
}
|
||||
|
||||
int FramelessWindowsManager::getTitleBarHeight(WindowId window)
|
||||
int FramelessWindowsManager::getTitleBarHeight(const QWindow *window)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -197,7 +188,7 @@ int FramelessWindowsManager::getTitleBarHeight(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setTitleBarHeight(WindowId window, const int value)
|
||||
void FramelessWindowsManager::setTitleBarHeight(const QWindow *window, const int value)
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Q_ASSERT(window);
|
||||
|
@ -211,7 +202,7 @@ void FramelessWindowsManager::setTitleBarHeight(WindowId window, const int value
|
|||
#endif
|
||||
}
|
||||
|
||||
bool FramelessWindowsManager::getResizable(WindowId window)
|
||||
bool FramelessWindowsManager::getResizable(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -222,7 +213,7 @@ bool FramelessWindowsManager::getResizable(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setResizable(WindowId window, const bool value)
|
||||
void FramelessWindowsManager::setResizable(const QWindow *window, const bool value)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -232,19 +223,18 @@ void FramelessWindowsManager::setResizable(WindowId window, const bool value)
|
|||
#endif
|
||||
}
|
||||
|
||||
QSize FramelessWindowsManager::getMinimumSize(WindowId window)
|
||||
QSize FramelessWindowsManager::getMinimumSize(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? data->minimumSize : QSize();
|
||||
#else
|
||||
const auto win = toWindow(window);
|
||||
return win ? win->minimumSize() : QSize();
|
||||
return window->minimumSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setMinimumSize(WindowId window, const QSize &value)
|
||||
void FramelessWindowsManager::setMinimumSize(const QWindow *window, const QSize &value)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -253,26 +243,22 @@ void FramelessWindowsManager::setMinimumSize(WindowId window, const QSize &value
|
|||
data->minimumSize = value;
|
||||
}
|
||||
#else
|
||||
const auto win = toWindow(window);
|
||||
if (win) {
|
||||
win->setMinimumSize(value);
|
||||
}
|
||||
window->setMinimumSize(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
QSize FramelessWindowsManager::getMaximumSize(WindowId window)
|
||||
QSize FramelessWindowsManager::getMaximumSize(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
const auto data = WinNativeEventFilter::getWindowData(window);
|
||||
return data ? data->maximumSize : QSize();
|
||||
#else
|
||||
const auto win = toWindow(window);
|
||||
return win ? win->maximumSize() : QSize();
|
||||
return window->maximumSize();
|
||||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setMaximumSize(WindowId window, const QSize &value)
|
||||
void FramelessWindowsManager::setMaximumSize(const QWindow *window, const QSize &value)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -281,14 +267,11 @@ void FramelessWindowsManager::setMaximumSize(WindowId window, const QSize &value
|
|||
data->maximumSize = value;
|
||||
}
|
||||
#else
|
||||
const auto win = toWindow(window);
|
||||
if (win) {
|
||||
win->setMaximumSize(value);
|
||||
}
|
||||
window->setMaximumSize(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool FramelessWindowsManager::getTitleBarEnabled(WindowId window)
|
||||
bool FramelessWindowsManager::getTitleBarEnabled(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
@ -299,7 +282,7 @@ bool FramelessWindowsManager::getTitleBarEnabled(WindowId window)
|
|||
#endif
|
||||
}
|
||||
|
||||
void FramelessWindowsManager::setTitleBarEnabled(WindowId window, const bool value)
|
||||
void FramelessWindowsManager::setTitleBarEnabled(const QWindow *window, const bool value)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
#ifdef Q_OS_WINDOWS
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QObject)
|
||||
QT_FORWARD_DECLARE_CLASS(QWindow)
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
|
||||
|
@ -51,45 +52,37 @@ class FRAMELESSHELPER_EXPORT FramelessWindowsManager
|
|||
Q_DISABLE_COPY_MOVE(FramelessWindowsManager)
|
||||
|
||||
public:
|
||||
using WindowId =
|
||||
#ifdef Q_OS_WINDOWS
|
||||
void *
|
||||
#else
|
||||
QObject *
|
||||
#endif
|
||||
;
|
||||
|
||||
explicit FramelessWindowsManager();
|
||||
~FramelessWindowsManager() = default;
|
||||
|
||||
static void addWindow(WindowId window, const bool center = false);
|
||||
static void addWindow(const QWindow *window, const bool center = false);
|
||||
|
||||
static void moveWindowToDesktopCenter(WindowId window);
|
||||
static void moveWindowToDesktopCenter(const QWindow *window);
|
||||
|
||||
static void addIgnoreArea(WindowId window, const QRect &area);
|
||||
static void addDraggableArea(WindowId window, const QRect &area);
|
||||
static void addIgnoreArea(const QWindow *window, const QRect &area);
|
||||
static void addDraggableArea(const QWindow *window, const QRect &area);
|
||||
|
||||
static void addIgnoreObject(WindowId window, QObject *object);
|
||||
static void addDraggableObject(WindowId window, QObject *object);
|
||||
static void addIgnoreObject(const QWindow *window, QObject *object);
|
||||
static void addDraggableObject(const QWindow *window, QObject *object);
|
||||
|
||||
static int getBorderWidth(WindowId window);
|
||||
static void setBorderWidth(WindowId window, const int value);
|
||||
static int getBorderWidth(const QWindow *window);
|
||||
static void setBorderWidth(const QWindow *window, const int value);
|
||||
|
||||
static int getBorderHeight(WindowId window);
|
||||
static void setBorderHeight(WindowId window, const int value);
|
||||
static int getBorderHeight(const QWindow *window);
|
||||
static void setBorderHeight(const QWindow *window, const int value);
|
||||
|
||||
static int getTitleBarHeight(WindowId window);
|
||||
static void setTitleBarHeight(WindowId window, const int value);
|
||||
static int getTitleBarHeight(const QWindow *window);
|
||||
static void setTitleBarHeight(const QWindow *window, const int value);
|
||||
|
||||
static bool getResizable(WindowId window);
|
||||
static void setResizable(WindowId window, const bool value = true);
|
||||
static bool getResizable(const QWindow *window);
|
||||
static void setResizable(const QWindow *window, const bool value = true);
|
||||
|
||||
static QSize getMinimumSize(WindowId window);
|
||||
static void setMinimumSize(WindowId window, const QSize &value);
|
||||
static QSize getMinimumSize(const QWindow *window);
|
||||
static void setMinimumSize(const QWindow *window, const QSize &value);
|
||||
|
||||
static QSize getMaximumSize(WindowId window);
|
||||
static void setMaximumSize(WindowId window, const QSize &value);
|
||||
static QSize getMaximumSize(const QWindow *window);
|
||||
static void setMaximumSize(const QWindow *window, const QSize &value);
|
||||
|
||||
static bool getTitleBarEnabled(WindowId window);
|
||||
static void setTitleBarEnabled(WindowId window, const bool value = true);
|
||||
static bool getTitleBarEnabled(const QWindow *window);
|
||||
static void setTitleBarEnabled(const QWindow *window, const bool value = true);
|
||||
};
|
||||
|
|
|
@ -1059,6 +1059,30 @@ int GetSystemMetricsForWindow(const HWND handle, const int index, const bool dpi
|
|||
return 0;
|
||||
}
|
||||
|
||||
QWindow *getWindowFromRawHandle(const HWND handle)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
const auto wid = reinterpret_cast<WId>(handle);
|
||||
const auto windows = QGuiApplication::topLevelWindows();
|
||||
for (auto &&window : qAsConst(windows)) {
|
||||
if (window && window->handle()) {
|
||||
if (window->winId() == wid) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
HWND getRawHandleFromWindow(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto handle = window->handle();
|
||||
return handle ? reinterpret_cast<HWND>(handle->winId()) : nullptr;
|
||||
}
|
||||
|
||||
void createUserData(const HWND handle, const WinNativeEventFilter::WINDOWDATA *data = nullptr)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
|
@ -1080,28 +1104,11 @@ void createUserData(const HWND handle, const WinNativeEventFilter::WINDOWDATA *d
|
|||
handle,
|
||||
GWLP_USERDATA,
|
||||
reinterpret_cast<LONG_PTR>(_data))
|
||||
WinNativeEventFilter::updateWindow(handle, true, false);
|
||||
WinNativeEventFilter::updateWindow(getWindowFromRawHandle(handle), true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QWindow *findQWindowFromRawHandle(const HWND handle)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
const auto wid = reinterpret_cast<WId>(handle);
|
||||
const auto windows = QGuiApplication::topLevelWindows();
|
||||
for (auto &&window : qAsConst(windows)) {
|
||||
if (window && window->handle()) {
|
||||
if (window->winId() == wid) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void qCoreAppFixup()
|
||||
{
|
||||
if (!QCoreApplication::testAttribute(Qt::AA_DontCreateNativeWidgetSiblings)) {
|
||||
|
@ -1113,39 +1120,24 @@ void updateQtFrame_internal(const HWND handle, const bool resetToDefault = false
|
|||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
const int tbh = resetToDefault
|
||||
? 0
|
||||
: WinNativeEventFilter::getSystemMetric(
|
||||
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight, true);
|
||||
QWindow *window = findQWindowFromRawHandle(handle);
|
||||
QWindow *window = getWindowFromRawHandle(handle);
|
||||
if (window) {
|
||||
const int tbh = resetToDefault ? 0
|
||||
: WinNativeEventFilter::getSystemMetric(
|
||||
window,
|
||||
WinNativeEventFilter::SystemMetric::TitleBarHeight,
|
||||
true);
|
||||
WinNativeEventFilter::updateQtFrame(window, tbh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool displaySystemMenu_internal(const HWND handle, const LPARAM lParam)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
POINT localMouse = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
||||
WNEF_EXECUTE_WINAPI(ScreenToClient, handle, &localMouse)
|
||||
const int tbh = WinNativeEventFilter::getSystemMetric(
|
||||
handle, WinNativeEventFilter::SystemMetric::TitleBarHeight, true);
|
||||
const bool isTitleBar = localMouse.y <= tbh;
|
||||
if (isTitleBar && !IsFullScreen(handle)) {
|
||||
return WinNativeEventFilter::displaySystemMenu(handle);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString getCurrentScreenIdentifier(const HWND handle)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) {
|
||||
QScreen *currentScreen = nullptr;
|
||||
const QWindow *window = findQWindowFromRawHandle(handle);
|
||||
const QWindow *window = getWindowFromRawHandle(handle);
|
||||
if (window) {
|
||||
currentScreen = window->screen();
|
||||
}
|
||||
|
@ -1193,7 +1185,7 @@ WinNativeEventFilter::WinNativeEventFilter()
|
|||
qCoreAppFixup();
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::addFramelessWindow(void *window,
|
||||
void WinNativeEventFilter::addFramelessWindow(const QWindow *window,
|
||||
const WINDOWDATA *data,
|
||||
const bool center,
|
||||
const int x,
|
||||
|
@ -1203,7 +1195,7 @@ void WinNativeEventFilter::addFramelessWindow(void *window,
|
|||
{
|
||||
Q_ASSERT(window);
|
||||
qCoreAppFixup();
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
createUserData(hwnd);
|
||||
const auto oldData = getWindowData(window);
|
||||
|
@ -1219,18 +1211,18 @@ void WinNativeEventFilter::addFramelessWindow(void *window,
|
|||
install();
|
||||
updateQtFrame_internal(hwnd);
|
||||
if ((x > 0) && (y > 0) && (width > 0) && (height > 0)) {
|
||||
setWindowGeometry(hwnd, x, y, width, height);
|
||||
setWindowGeometry(window, x, y, width, height);
|
||||
}
|
||||
if (center) {
|
||||
moveWindowToDesktopCenter(hwnd);
|
||||
moveWindowToDesktopCenter(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::removeFramelessWindow(void *window)
|
||||
void WinNativeEventFilter::removeFramelessWindow(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
createUserData(hwnd);
|
||||
const auto data = getWindowData(window);
|
||||
if (data) {
|
||||
|
@ -1262,7 +1254,9 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// The example code in Qt's documentation has this check. I don't know
|
||||
// whether we really need this check or not, but adding this check won't
|
||||
// bring us harm anyway.
|
||||
if (eventType == "windows_generic_MSG") {
|
||||
if (eventType != "windows_generic_MSG") {
|
||||
return false;
|
||||
}
|
||||
#if (QT_VERSION == QT_VERSION_CHECK(5, 11, 1))
|
||||
// Work-around a bug caused by typo which only exists in Qt 5.11.1
|
||||
const auto msg = *reinterpret_cast<MSG **>(message);
|
||||
|
@ -1274,6 +1268,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// Anyway, we should skip it in this case.
|
||||
return false;
|
||||
}
|
||||
const QWindow *window = getWindowFromRawHandle(msg->hwnd);
|
||||
const auto data = reinterpret_cast<WINDOWDATA *>(
|
||||
WNEF_EXECUTE_WINAPI_RETURN(GetWindowLongPtrW, 0, msg->hwnd, GWLP_USERDATA));
|
||||
if (!data) {
|
||||
|
@ -1292,7 +1287,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// you must call SetWindowPos for the changes to take effect.
|
||||
// Use the following combination for uFlags: SWP_NOMOVE |
|
||||
// SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED.
|
||||
updateWindow(msg->hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
}
|
||||
*result = WNEF_EXECUTE_WINAPI_RETURN(DefWindowProcW,
|
||||
0,
|
||||
|
@ -1330,7 +1325,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
msg->hwnd,
|
||||
GWL_STYLE,
|
||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS)
|
||||
updateWindow(msg->hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
}
|
||||
if (data->enableLayeredWindow) {
|
||||
// Turn our window into a layered window to get better
|
||||
|
@ -1348,7 +1343,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
msg->hwnd,
|
||||
GWL_EXSTYLE)
|
||||
| WS_EX_LAYERED)
|
||||
updateWindow(msg->hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
// A layered window can't be visible unless we call
|
||||
// SetLayeredWindowAttributes or UpdateLayeredWindow once.
|
||||
WNEF_EXECUTE_WINAPI(SetLayeredWindowAttributes,
|
||||
|
@ -1360,7 +1355,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// Bring our frame shadow back through DWM, don't draw it manually.
|
||||
UpdateFrameMarginsForWindow(msg->hwnd);
|
||||
// Blur effect.
|
||||
setBlurEffectEnabled(msg->hwnd, data->enableBlurBehindWindow);
|
||||
setBlurEffectEnabled(window, data->enableBlurBehindWindow);
|
||||
}
|
||||
switch (msg->message) {
|
||||
case WM_NCCALCSIZE: {
|
||||
|
@ -1445,8 +1440,8 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// actions like resizing a window from the left edge look slightly
|
||||
// less broken.
|
||||
*result = mode ? WVR_REDRAW : 0;
|
||||
const auto clientRect = mode ? &(
|
||||
reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0])
|
||||
const auto clientRect = mode
|
||||
? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(msg->lParam)->rgrc[0])
|
||||
: reinterpret_cast<LPRECT>(msg->lParam);
|
||||
if (shouldHaveWindowFrame()) {
|
||||
// Store the original top before the default window proc
|
||||
|
@ -1478,11 +1473,11 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// The value of border width and border height should be
|
||||
// identical in most cases, when the scale factor is 1.0, it
|
||||
// should be eight pixels.
|
||||
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||
const int bh = getSystemMetric(window, SystemMetric::BorderHeight, true);
|
||||
clientRect->top += bh;
|
||||
if (!shouldHaveWindowFrame()) {
|
||||
clientRect->bottom -= bh;
|
||||
const int bw = getSystemMetric(msg->hwnd, SystemMetric::BorderWidth, true);
|
||||
const int bw = getSystemMetric(window, SystemMetric::BorderWidth, true);
|
||||
clientRect->left += bw;
|
||||
clientRect->right -= bw;
|
||||
}
|
||||
|
@ -1738,19 +1733,15 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
if (!area.isValid()) {
|
||||
continue;
|
||||
}
|
||||
if (QRectF(area.x() * dpr,
|
||||
area.y() * dpr,
|
||||
area.width() * dpr,
|
||||
area.height() * dpr)
|
||||
if (QRectF(area.x() * dpr, area.y() * dpr, area.width() * dpr, area.height() * dpr)
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const auto isInSpecificObjects = [](const QPointF &mousePos,
|
||||
const QList<QObject *> &objects,
|
||||
const qreal dpr) -> bool {
|
||||
const auto isInSpecificObjects =
|
||||
[](const QPointF &mousePos, const QList<QObject *> &objects, const qreal dpr) -> bool {
|
||||
if (objects.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1768,18 +1759,14 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
Q_ASSERT(obj);
|
||||
QPointF point = {obj->property("x").toReal(), obj->property("y").toReal()};
|
||||
for (QObject *parent = obj->parent(); parent; parent = parent->parent()) {
|
||||
point += {parent->property("x").toReal(),
|
||||
parent->property("y").toReal()};
|
||||
point += {parent->property("x").toReal(), parent->property("y").toReal()};
|
||||
}
|
||||
return point;
|
||||
};
|
||||
const QPointF originPoint = mapOriginPointToWindow(object);
|
||||
const qreal width = object->property("width").toReal();
|
||||
const qreal height = object->property("height").toReal();
|
||||
if (QRectF(originPoint.x() * dpr,
|
||||
originPoint.y() * dpr,
|
||||
width * dpr,
|
||||
height * dpr)
|
||||
if (QRectF(originPoint.x() * dpr, originPoint.y() * dpr, width * dpr, height * dpr)
|
||||
.contains(mousePos)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1794,14 +1781,11 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
static_cast<qreal>(winLocalMouse.y)};
|
||||
const bool isInIgnoreAreas = isInSpecificAreas(localMouse, data->ignoreAreas, dpr);
|
||||
const bool customDragAreas = !data->draggableAreas.isEmpty();
|
||||
const bool isInDraggableAreas = customDragAreas
|
||||
? isInSpecificAreas(localMouse,
|
||||
const bool isInDraggableAreas = customDragAreas ? isInSpecificAreas(localMouse,
|
||||
data->draggableAreas,
|
||||
dpr)
|
||||
: true;
|
||||
const bool isInIgnoreObjects = isInSpecificObjects(globalMouse,
|
||||
data->ignoreObjects,
|
||||
dpr);
|
||||
const bool isInIgnoreObjects = isInSpecificObjects(globalMouse, data->ignoreObjects, dpr);
|
||||
const bool customDragObjects = !data->draggableObjects.isEmpty();
|
||||
const bool isInDraggableObjects = customDragObjects
|
||||
? isInSpecificObjects(globalMouse,
|
||||
|
@ -1810,8 +1794,8 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
: true;
|
||||
const bool customDrag = customDragAreas || customDragObjects;
|
||||
const bool isResizePermitted = !isInIgnoreAreas && !isInIgnoreObjects;
|
||||
const int bh = getSystemMetric(msg->hwnd, SystemMetric::BorderHeight, true);
|
||||
const int tbh = getSystemMetric(msg->hwnd, SystemMetric::TitleBarHeight, true);
|
||||
const int bh = getSystemMetric(window, SystemMetric::BorderHeight, true);
|
||||
const int tbh = getSystemMetric(window, SystemMetric::TitleBarHeight, true);
|
||||
const bool isTitleBar = (customDrag ? (isInDraggableAreas && isInDraggableObjects)
|
||||
: (localMouse.y() <= tbh))
|
||||
&& isResizePermitted && !data->disableTitleBar;
|
||||
|
@ -1846,12 +1830,12 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
return true;
|
||||
} else {
|
||||
const auto getHitTestResult =
|
||||
[msg, isTitleBar, &localMouse, bh, isTop, data]() -> LRESULT {
|
||||
[msg, isTitleBar, &localMouse, bh, isTop, data, window]() -> LRESULT {
|
||||
RECT clientRect = {0, 0, 0, 0};
|
||||
WNEF_EXECUTE_WINAPI(GetClientRect, msg->hwnd, &clientRect)
|
||||
const LONG ww = clientRect.right;
|
||||
const LONG wh = clientRect.bottom;
|
||||
const int bw = getSystemMetric(msg->hwnd, SystemMetric::BorderWidth, true);
|
||||
const int bw = getSystemMetric(window, SystemMetric::BorderWidth, true);
|
||||
if (IsMaximized(msg->hwnd)) {
|
||||
if (isTitleBar) {
|
||||
return HTCAPTION;
|
||||
|
@ -1946,14 +1930,11 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
|
||||
// Disable painting while these messages are handled to prevent them
|
||||
// from drawing a window caption over the client area.
|
||||
const auto oldStyle = WNEF_EXECUTE_WINAPI_RETURN(GetWindowLongPtrW,
|
||||
0,
|
||||
msg->hwnd,
|
||||
GWL_STYLE);
|
||||
const auto oldStyle = WNEF_EXECUTE_WINAPI_RETURN(GetWindowLongPtrW, 0, msg->hwnd, GWL_STYLE);
|
||||
// Prevent Windows from drawing the default title bar by temporarily
|
||||
// toggling the WS_VISIBLE style.
|
||||
WNEF_EXECUTE_WINAPI(SetWindowLongPtrW, msg->hwnd, GWL_STYLE, oldStyle & ~WS_VISIBLE)
|
||||
updateWindow(msg->hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
const LRESULT ret = WNEF_EXECUTE_WINAPI_RETURN(DefWindowProcW,
|
||||
0,
|
||||
msg->hwnd,
|
||||
|
@ -1961,7 +1942,7 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
msg->wParam,
|
||||
msg->lParam);
|
||||
WNEF_EXECUTE_WINAPI(SetWindowLongPtrW, msg->hwnd, GWL_STYLE, oldStyle)
|
||||
updateWindow(msg->hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
*result = ret;
|
||||
return true;
|
||||
}
|
||||
|
@ -2000,23 +1981,6 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
// to do this yourself. See:
|
||||
// https://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/windows/qwindowscontext.cpp
|
||||
break;
|
||||
case WM_CONTEXTMENU: {
|
||||
if (shouldUseNativeTitleBar()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If the context menu is brought up from the keyboard
|
||||
// (SHIFT + F10 or the context menu key), lParam will be -1.
|
||||
const LPARAM lParam = (msg->lParam == -1) ? WNEF_EXECUTE_WINAPI_RETURN(GetMessagePos, 0)
|
||||
: msg->lParam;
|
||||
if (displaySystemMenu_internal(msg->hwnd, lParam)) {
|
||||
// The WM_CONTEXTMENU message has no return value so there's
|
||||
// no need to modify *result.
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
case WM_MOVE: {
|
||||
if (shouldUseNativeTitleBar()) {
|
||||
break;
|
||||
|
@ -2025,30 +1989,29 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
|
|||
const QString sn = getCurrentScreenIdentifier(msg->hwnd);
|
||||
if (data->currentScreen.toUpper() != sn) {
|
||||
data->currentScreen = sn;
|
||||
updateWindow(msg->hwnd, true, true);
|
||||
updateWindow(window, true, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::setWindowData(void *window, const WINDOWDATA *data)
|
||||
void WinNativeEventFilter::setWindowData(const QWindow *window, const WINDOWDATA *data)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd) && data) {
|
||||
createUserData(hwnd, data);
|
||||
}
|
||||
}
|
||||
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::getWindowData(void *window)
|
||||
WinNativeEventFilter::WINDOWDATA *WinNativeEventFilter::getWindowData(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(window);
|
||||
const auto hwnd = reinterpret_cast<HWND>(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
createUserData(hwnd);
|
||||
return reinterpret_cast<WINDOWDATA *>(
|
||||
|
@ -2072,12 +2035,12 @@ void WinNativeEventFilter::setTitleBarHeight(const int tbh)
|
|||
coreData()->m_titleBarHeight = tbh;
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::updateWindow(void *handle,
|
||||
void WinNativeEventFilter::updateWindow(const QWindow *window,
|
||||
const bool triggerFrameChange,
|
||||
const bool redraw)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
if (triggerFrameChange) {
|
||||
WNEF_EXECUTE_WINAPI(SetWindowPos,
|
||||
|
@ -2100,12 +2063,12 @@ void WinNativeEventFilter::updateWindow(void *handle,
|
|||
}
|
||||
}
|
||||
|
||||
int WinNativeEventFilter::getSystemMetric(void *handle,
|
||||
int WinNativeEventFilter::getSystemMetric(const QWindow *window,
|
||||
const SystemMetric metric,
|
||||
const bool dpiAware)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
const qreal dpr = dpiAware ? GetDevicePixelRatioForWindow(hwnd) : m_defaultDevicePixelRatio;
|
||||
int ret = 0;
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
|
@ -2163,7 +2126,7 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
|||
// dpr = 1.5 --> Title Bar Height = 45px
|
||||
// dpr = 1.75 --> Title Bar Height = 51px
|
||||
ret += (metric == SystemMetric::TitleBarHeight)
|
||||
? getSystemMetric(handle, SystemMetric::BorderHeight, dpiAware)
|
||||
? getSystemMetric(window, SystemMetric::BorderHeight, dpiAware)
|
||||
: 0;
|
||||
return ret;
|
||||
}
|
||||
|
@ -2194,10 +2157,10 @@ int WinNativeEventFilter::getSystemMetric(void *handle,
|
|||
}
|
||||
|
||||
void WinNativeEventFilter::setWindowGeometry(
|
||||
void *handle, const int x, const int y, const int width, const int height)
|
||||
const QWindow *window, const int x, const int y, const int width, const int height)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd) && (x > 0) && (y > 0) && (width > 0)
|
||||
&& (height > 0)) {
|
||||
const qreal dpr = GetDevicePixelRatioForWindow(hwnd);
|
||||
|
@ -2209,10 +2172,10 @@ void WinNativeEventFilter::setWindowGeometry(
|
|||
}
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::moveWindowToDesktopCenter(void *handle)
|
||||
void WinNativeEventFilter::moveWindowToDesktopCenter(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
const WINDOWINFO windowInfo = GetInfoForWindow(hwnd);
|
||||
const MONITORINFO monitorInfo = GetMonitorInfoForWindow(hwnd);
|
||||
|
@ -2263,10 +2226,10 @@ void WinNativeEventFilter::updateQtFrame(QWindow *window, const int titleBarHeig
|
|||
}
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::displaySystemMenu(void *handle, const QPointF &pos)
|
||||
bool WinNativeEventFilter::displaySystemMenu(const QWindow *window, const QPointF &pos)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
const HMENU hMenu = WNEF_EXECUTE_WINAPI_RETURN(GetSystemMenu, nullptr, hwnd, FALSE);
|
||||
if (hMenu) {
|
||||
|
@ -2282,7 +2245,7 @@ bool WinNativeEventFilter::displaySystemMenu(void *handle, const QPointF &pos)
|
|||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_MAXIMIZE, FALSE, &mii)
|
||||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_MINIMIZE, FALSE, &mii)
|
||||
mii.fState = MF_GRAYED;
|
||||
const auto data = getWindowData(hwnd);
|
||||
const auto data = getWindowData(window);
|
||||
const bool fixedSize = data ? data->fixedSize : false;
|
||||
if (fixedSize) {
|
||||
WNEF_EXECUTE_WINAPI(SetMenuItemInfoW, hMenu, SC_SIZE, FALSE, &mii)
|
||||
|
@ -2302,14 +2265,13 @@ bool WinNativeEventFilter::displaySystemMenu(void *handle, const QPointF &pos)
|
|||
const QPointF mousePos = pos.isNull()
|
||||
? QCursor::pos() * GetDevicePixelRatioForWindow(hwnd)
|
||||
: pos;
|
||||
const bool isRightToLeft = QGuiApplication::layoutDirection() == Qt::RightToLeft;
|
||||
const LPARAM cmd = WNEF_EXECUTE_WINAPI_RETURN(TrackPopupMenu,
|
||||
0,
|
||||
hMenu,
|
||||
(TPM_LEFTBUTTON | TPM_RIGHTBUTTON
|
||||
| TPM_RETURNCMD | TPM_TOPALIGN
|
||||
| (QGuiApplication::layoutDirection()
|
||||
== Qt::RightToLeft
|
||||
? TPM_RIGHTALIGN
|
||||
| (isRightToLeft ? TPM_RIGHTALIGN
|
||||
: TPM_LEFTALIGN)),
|
||||
qRound(mousePos.x()),
|
||||
qRound(mousePos.y()),
|
||||
|
@ -2325,12 +2287,12 @@ bool WinNativeEventFilter::displaySystemMenu(void *handle, const QPointF &pos)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::setBlurEffectEnabled(void *handle,
|
||||
bool WinNativeEventFilter::setBlurEffectEnabled(const QWindow *window,
|
||||
const bool enabled,
|
||||
const QColor &gradientColor)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
#ifdef QT_WIDGETS_LIB
|
||||
// Is it possible to set a palette to a QWindow?
|
||||
|
@ -2402,21 +2364,21 @@ bool WinNativeEventFilter::setBlurEffectEnabled(void *handle,
|
|||
return false;
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::updateFrameMargins(void *handle)
|
||||
void WinNativeEventFilter::updateFrameMargins(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
UpdateFrameMarginsForWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
void WinNativeEventFilter::setWindowResizable(void *handle, const bool resizable)
|
||||
void WinNativeEventFilter::setWindowResizable(const QWindow *window, const bool resizable)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
Q_ASSERT(window);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
const auto data = getWindowData(hwnd);
|
||||
const auto data = getWindowData(window);
|
||||
if (data) {
|
||||
data->fixedSize = !resizable;
|
||||
}
|
||||
|
@ -2429,7 +2391,7 @@ void WinNativeEventFilter::setWindowResizable(void *handle, const bool resizable
|
|||
hwnd,
|
||||
GWL_STYLE,
|
||||
resizable ? resizableStyle : fixedSizeStyle)
|
||||
updateWindow(hwnd, true, false);
|
||||
updateWindow(window, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2476,13 +2438,13 @@ bool WinNativeEventFilter::isHighContrastModeEnabled()
|
|||
: false;
|
||||
}
|
||||
|
||||
bool WinNativeEventFilter::isDarkFrameEnabled(void *handle)
|
||||
bool WinNativeEventFilter::isDarkFrameEnabled(const QWindow *window)
|
||||
{
|
||||
Q_ASSERT(handle);
|
||||
Q_ASSERT(window);
|
||||
if (!isWin10OrGreater(17763)) {
|
||||
return false;
|
||||
}
|
||||
const auto hwnd = reinterpret_cast<HWND>(handle);
|
||||
const HWND hwnd = getRawHandleFromWindow(window);
|
||||
if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, hwnd)) {
|
||||
BOOL result = FALSE;
|
||||
const bool ok = SUCCEEDED(WNEF_EXECUTE_WINAPI_RETURN(DwmGetWindowAttribute,
|
||||
|
|
|
@ -72,23 +72,23 @@ public:
|
|||
// The width and height will be scaled automatically according to DPI. Don't
|
||||
// scale them yourself. Just pass the original value. If you don't want to
|
||||
// change them, pass negative values to the parameters.
|
||||
static void addFramelessWindow(void *window /* HWND */,
|
||||
static void addFramelessWindow(const QWindow *window,
|
||||
const WINDOWDATA *data = nullptr,
|
||||
const bool center = false,
|
||||
const int x = -1,
|
||||
const int y = -1,
|
||||
const int width = -1,
|
||||
const int height = -1);
|
||||
static void removeFramelessWindow(void *window /* HWND */);
|
||||
static void removeFramelessWindow(const QWindow *window);
|
||||
|
||||
// Set borderWidth, borderHeight or titleBarHeight to a negative value to
|
||||
// restore default behavior.
|
||||
// Note that it can only affect one specific window.
|
||||
// If you want to change these values globally, use setBorderWidth instead.
|
||||
static void setWindowData(void *window /* HWND */, const WINDOWDATA *data);
|
||||
static void setWindowData(const QWindow *window, const WINDOWDATA *data);
|
||||
// You can modify the given window's data directly, it's the same with using
|
||||
// setWindowData.
|
||||
static WINDOWDATA *getWindowData(void *window /* HWND */);
|
||||
static WINDOWDATA *getWindowData(const QWindow *window);
|
||||
|
||||
// Change settings globally, not a specific window.
|
||||
// These values will be scaled automatically according to DPI, don't scale
|
||||
|
@ -99,14 +99,14 @@ public:
|
|||
|
||||
// System metric value of the given window (if the pointer is null,
|
||||
// return the system's standard value).
|
||||
static int getSystemMetric(void *handle /* HWND */,
|
||||
static int getSystemMetric(const QWindow *window,
|
||||
const SystemMetric metric,
|
||||
const bool dpiAware = false);
|
||||
|
||||
// Use this function to trigger a frame change event or redraw a
|
||||
// specific window. Useful when you want to let some changes
|
||||
// in effect immediately.
|
||||
static void updateWindow(void *handle /* HWND */,
|
||||
static void updateWindow(const QWindow *window,
|
||||
const bool triggerFrameChange = true,
|
||||
const bool redraw = true);
|
||||
|
||||
|
@ -114,10 +114,10 @@ public:
|
|||
// The width and height will be scaled automatically according to DPI. So
|
||||
// just pass the original value.
|
||||
static void setWindowGeometry(
|
||||
void *handle /* HWND */, const int x, const int y, const int width, const int height);
|
||||
const QWindow *window, const int x, const int y, const int width, const int height);
|
||||
|
||||
// Move the window to the center of the desktop.
|
||||
static void moveWindowToDesktopCenter(void *handle /* HWND */);
|
||||
static void moveWindowToDesktopCenter(const QWindow *window);
|
||||
|
||||
// Update Qt's internal data about the window frame, otherwise Qt will
|
||||
// take the size of the window frame into account when anyone is trying to
|
||||
|
@ -125,20 +125,20 @@ public:
|
|||
static void updateQtFrame(QWindow *window, const int titleBarHeight);
|
||||
|
||||
// Display the system context menu.
|
||||
static bool displaySystemMenu(void *handle /* HWND */, const QPointF &pos = {});
|
||||
static bool displaySystemMenu(const QWindow *window, const QPointF &pos = {});
|
||||
|
||||
// Enable or disable the blur effect for a specific window.
|
||||
// On Win10 it's the Acrylic effect.
|
||||
static bool setBlurEffectEnabled(void *handle /* HWND */,
|
||||
static bool setBlurEffectEnabled(const QWindow *window,
|
||||
const bool enabled = true,
|
||||
const QColor &gradientColor = Qt::white);
|
||||
|
||||
// Thin wrapper of DwmExtendFrameIntoClientArea().
|
||||
static void updateFrameMargins(void *handle /* HWND */);
|
||||
static void updateFrameMargins(const QWindow *window);
|
||||
|
||||
// A resizable window can be resized and maximized, however, a fixed size
|
||||
// window can only be moved and minimized, it can't be resized and maximized.
|
||||
static void setWindowResizable(void *handle /* HWND */, const bool resizable = true);
|
||||
static void setWindowResizable(const QWindow *window, const bool resizable = true);
|
||||
|
||||
// Query whether colorization is enabled or not.
|
||||
static bool isColorizationEnabled();
|
||||
|
@ -156,7 +156,7 @@ public:
|
|||
static bool isHighContrastModeEnabled();
|
||||
|
||||
// Query whether the given window is using dark frame or not.
|
||||
static bool isDarkFrameEnabled(void *handle /* HWND */);
|
||||
static bool isDarkFrameEnabled(const QWindow *window);
|
||||
|
||||
// Query whether the transparency effect is enabled or not.
|
||||
static bool isTransparencyEffectEnabled();
|
||||
|
|
Loading…
Reference in New Issue