forked from github_mirror/framelesshelper
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);
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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