parent
5ecc06df2f
commit
d3157699ef
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include "framelesshelpercore_global.h"
|
#include "framelesshelpercore_global.h"
|
||||||
#include <QtGui/qwindowdefs.h>
|
#include <QtGui/qwindowdefs.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
FRAMELESSHELPER_BEGIN_NAMESPACE
|
FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
@ -67,6 +68,9 @@ enum class DwmColorizationArea : int
|
||||||
Q_ENUM_NS(DwmColorizationArea)
|
Q_ENUM_NS(DwmColorizationArea)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
|
||||||
|
using SetWindowFlagsCallback = std::function<void(Qt::WindowFlags)>;
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -114,7 +118,8 @@ FRAMELESSHELPER_CORE_API void fixupQtInternals(const WId winId);
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isFrameBorderColorized();
|
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isFrameBorderColorized();
|
||||||
FRAMELESSHELPER_CORE_API void installSystemMenuHook(const QWindow *window);
|
FRAMELESSHELPER_CORE_API void installSystemMenuHook(const QWindow *window);
|
||||||
FRAMELESSHELPER_CORE_API void uninstallSystemMenuHook(const WId winId);
|
FRAMELESSHELPER_CORE_API void uninstallSystemMenuHook(const WId winId);
|
||||||
FRAMELESSHELPER_CORE_API void tryToBeCompatibleWithQtFramelessWindowHint(QWindow *window, const bool enable);
|
FRAMELESSHELPER_CORE_API void tryToBeCompatibleWithQtFramelessWindowHint(const WId winId,
|
||||||
|
const GetWindowFlagsCallback &getWindowFlags, const SetWindowFlagsCallback &setWindowFlags, const bool enable);
|
||||||
#endif // Q_OS_WINDOWS
|
#endif // Q_OS_WINDOWS
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
|
@ -1078,13 +1078,17 @@ void Utils::sendMouseReleaseEvent()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Utils::tryToBeCompatibleWithQtFramelessWindowHint(QWindow *window, const bool enable)
|
void Utils::tryToBeCompatibleWithQtFramelessWindowHint(const WId winId,
|
||||||
|
const GetWindowFlagsCallback &getWindowFlags,
|
||||||
|
const SetWindowFlagsCallback &setWindowFlags,
|
||||||
|
const bool enable)
|
||||||
{
|
{
|
||||||
Q_ASSERT(window);
|
Q_ASSERT(winId);
|
||||||
if (!window) {
|
Q_ASSERT(getWindowFlags);
|
||||||
|
Q_ASSERT(setWindowFlags);
|
||||||
|
if (!winId || !getWindowFlags || !setWindowFlags) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const WId winId = window->winId();
|
|
||||||
const auto hwnd = reinterpret_cast<HWND>(winId);
|
const auto hwnd = reinterpret_cast<HWND>(winId);
|
||||||
SetLastError(ERROR_SUCCESS);
|
SetLastError(ERROR_SUCCESS);
|
||||||
const LONG_PTR originalWindowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
|
const LONG_PTR originalWindowStyle = GetWindowLongPtrW(hwnd, GWL_STYLE);
|
||||||
|
@ -1092,10 +1096,10 @@ void Utils::tryToBeCompatibleWithQtFramelessWindowHint(QWindow *window, const bo
|
||||||
qWarning() << getSystemErrorMessage(QStringLiteral("GetWindowLongPtrW"));
|
qWarning() << getSystemErrorMessage(QStringLiteral("GetWindowLongPtrW"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const Qt::WindowFlags originalWindowFlags = window->flags();
|
const Qt::WindowFlags originalWindowFlags = getWindowFlags();
|
||||||
const Qt::WindowFlags newWindowFlags = (enable ? (originalWindowFlags | Qt::FramelessWindowHint)
|
const Qt::WindowFlags newWindowFlags = (enable ? (originalWindowFlags | Qt::FramelessWindowHint)
|
||||||
: (originalWindowFlags & ~Qt::FramelessWindowHint));
|
: (originalWindowFlags & ~Qt::FramelessWindowHint));
|
||||||
window->setFlags(newWindowFlags);
|
setWindowFlags(newWindowFlags);
|
||||||
SetLastError(ERROR_SUCCESS);
|
SetLastError(ERROR_SUCCESS);
|
||||||
if (SetWindowLongPtrW(hwnd, GWL_STYLE, originalWindowStyle) == 0) {
|
if (SetWindowLongPtrW(hwnd, GWL_STYLE, originalWindowStyle) == 0) {
|
||||||
qWarning() << getSystemErrorMessage(QStringLiteral("SetWindowLongPtrW"));
|
qWarning() << getSystemErrorMessage(QStringLiteral("SetWindowLongPtrW"));
|
||||||
|
|
|
@ -309,8 +309,10 @@ void FramelessWidgetsHelper::initialize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_options & Option::BeCompatibleWithQtFramelessWindowHint) {
|
if (m_options & Option::BeCompatibleWithQtFramelessWindowHint) {
|
||||||
Utils::tryToBeCompatibleWithQtFramelessWindowHint(window, true);
|
Utils::tryToBeCompatibleWithQtFramelessWindowHint(q->winId(),
|
||||||
Q_ASSERT(window->flags() & Qt::FramelessWindowHint);
|
[this]() -> Qt::WindowFlags { return q->windowFlags(); },
|
||||||
|
[this](Qt::WindowFlags flags) -> void { q->setWindowFlags(flags); },
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
FramelessWindowsManager *manager = FramelessWindowsManager::instance();
|
FramelessWindowsManager *manager = FramelessWindowsManager::instance();
|
||||||
manager->addWindow(window);
|
manager->addWindow(window);
|
||||||
|
|
Loading…
Reference in New Issue