Linux: fix mouse release event not being sent due to wrong parameter
Also simplifies a little Windows implementation. Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
3d7576e062
commit
fd2b3f5e84
|
@ -281,6 +281,98 @@ enum class ButtonState
|
||||||
};
|
};
|
||||||
Q_ENUM_NS(ButtonState)
|
Q_ENUM_NS(ButtonState)
|
||||||
|
|
||||||
|
enum class WindowsVersion
|
||||||
|
{
|
||||||
|
_2000 = 0,
|
||||||
|
_XP = 1,
|
||||||
|
_XP_64 = 2,
|
||||||
|
_Vista = 3,
|
||||||
|
_Vista_SP1 = 4,
|
||||||
|
_Vista_SP2 = 5,
|
||||||
|
_7 = 6,
|
||||||
|
_7_SP1 = 7,
|
||||||
|
_8 = 8,
|
||||||
|
_8_1 = 9,
|
||||||
|
_8_1_Update1 = 10,
|
||||||
|
_10_1507 = 11,
|
||||||
|
_10_1511 = 12,
|
||||||
|
_10_1607 = 13,
|
||||||
|
_10_1703 = 14,
|
||||||
|
_10_1709 = 15,
|
||||||
|
_10_1803 = 16,
|
||||||
|
_10_1809 = 17,
|
||||||
|
_10_1903 = 18,
|
||||||
|
_10_1909 = 19,
|
||||||
|
_10_2004 = 20,
|
||||||
|
_10_20H2 = 21,
|
||||||
|
_10_21H1 = 22,
|
||||||
|
_10_21H2 = 23,
|
||||||
|
_11_21H2 = 24
|
||||||
|
};
|
||||||
|
Q_ENUM_NS(WindowsVersion)
|
||||||
|
|
||||||
|
struct VersionNumber
|
||||||
|
{
|
||||||
|
int major = 0;
|
||||||
|
int minor = 0;
|
||||||
|
int patch = 0;
|
||||||
|
int tweak = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator==(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
return ((lhs.major == rhs.major) && (lhs.minor == rhs.minor) && (lhs.patch == rhs.patch) && (lhs.tweak == rhs.tweak));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator!=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator>(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
if (lhs.major > rhs.major) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (lhs.major < rhs.major) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (lhs.minor > rhs.minor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (lhs.minor < rhs.minor) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (lhs.patch > rhs.patch) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (lhs.patch < rhs.patch) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (lhs.tweak > rhs.tweak) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (lhs.tweak < rhs.tweak) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator<(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
return ((lhs != rhs) && !(lhs > rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator>=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
return ((lhs > rhs) || (lhs == rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] friend bool operator<=(const VersionNumber &lhs, const VersionNumber &rhs) noexcept
|
||||||
|
{
|
||||||
|
return ((lhs < rhs) || (lhs == rhs));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
|
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
|
||||||
using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>;
|
using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>;
|
||||||
|
|
||||||
|
@ -361,6 +453,25 @@ struct SystemParameters
|
||||||
|
|
||||||
[[nodiscard]] inline bool isValid() const
|
[[nodiscard]] inline bool isValid() const
|
||||||
{
|
{
|
||||||
|
Q_ASSERT(getWindowFlags);
|
||||||
|
Q_ASSERT(setWindowFlags);
|
||||||
|
Q_ASSERT(getWindowSize);
|
||||||
|
Q_ASSERT(setWindowSize);
|
||||||
|
Q_ASSERT(getWindowPosition);
|
||||||
|
Q_ASSERT(setWindowPosition);
|
||||||
|
Q_ASSERT(getWindowScreen);
|
||||||
|
Q_ASSERT(isWindowFixedSize);
|
||||||
|
Q_ASSERT(setWindowFixedSize);
|
||||||
|
Q_ASSERT(getWindowState);
|
||||||
|
Q_ASSERT(setWindowState);
|
||||||
|
Q_ASSERT(getWindowHandle);
|
||||||
|
Q_ASSERT(windowToScreen);
|
||||||
|
Q_ASSERT(screenToWindow);
|
||||||
|
Q_ASSERT(isInsideSystemButtons);
|
||||||
|
Q_ASSERT(isInsideTitleBarDraggableArea);
|
||||||
|
Q_ASSERT(getWindowDevicePixelRatio);
|
||||||
|
Q_ASSERT(setSystemButtonState);
|
||||||
|
Q_ASSERT(getWindowId);
|
||||||
return (getWindowFlags && setWindowFlags && getWindowSize
|
return (getWindowFlags && setWindowFlags && getWindowSize
|
||||||
&& setWindowSize && getWindowPosition && setWindowPosition
|
&& setWindowSize && getWindowPosition && setWindowPosition
|
||||||
&& getWindowScreen && isWindowFixedSize && setWindowFixedSize
|
&& getWindowScreen && isWindowFixedSize && setWindowFixedSize
|
||||||
|
@ -371,6 +482,36 @@ struct SystemParameters
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[[maybe_unused]] static constexpr const VersionNumber WindowsVersions[] =
|
||||||
|
{
|
||||||
|
{ 5, 0, 2195}, // Windows 2000
|
||||||
|
{ 5, 1, 2600}, // Windows XP
|
||||||
|
{ 5, 2, 3790}, // Windows XP x64 Edition or Windows Server 2003
|
||||||
|
{ 6, 0, 6000}, // Windows Vista
|
||||||
|
{ 6, 0, 6001}, // Windows Vista with Service Pack 1 or Windows Server 2008
|
||||||
|
{ 6, 0, 6002}, // Windows Vista with Service Pack 2
|
||||||
|
{ 6, 1, 7600}, // Windows 7 or Windows Server 2008 R2
|
||||||
|
{ 6, 1, 7601}, // Windows 7 with Service Pack 1 or Windows Server 2008 R2 with Service Pack 1
|
||||||
|
{ 6, 2, 9200}, // Windows 8 or Windows Server 2012
|
||||||
|
{ 6, 3, 9200}, // Windows 8.1 or Windows Server 2012 R2
|
||||||
|
{ 6, 3, 9600}, // Windows 8.1 with Update 1
|
||||||
|
{10, 0, 10240}, // Windows 10 Version 1507 (TH1)
|
||||||
|
{10, 0, 10586}, // Windows 10 Version 1511 (November Update) (TH2)
|
||||||
|
{10, 0, 14393}, // Windows 10 Version 1607 (Anniversary Update) (RS1) or Windows Server 2016
|
||||||
|
{10, 0, 15063}, // Windows 10 Version 1703 (Creators Update) (RS2)
|
||||||
|
{10, 0, 16299}, // Windows 10 Version 1709 (Fall Creators Update) (RS3)
|
||||||
|
{10, 0, 17134}, // Windows 10 Version 1803 (April 2018 Update) (RS4)
|
||||||
|
{10, 0, 17763}, // Windows 10 Version 1809 (October 2018 Update) (RS5) or Windows Server 2019
|
||||||
|
{10, 0, 18362}, // Windows 10 Version 1903 (May 2019 Update) (19H1)
|
||||||
|
{10, 0, 18363}, // Windows 10 Version 1909 (November 2019 Update) (19H2)
|
||||||
|
{10, 0, 19041}, // Windows 10 Version 2004 (May 2020 Update) (20H1)
|
||||||
|
{10, 0, 19042}, // Windows 10 Version 20H2 (October 2020 Update) (20H2)
|
||||||
|
{10, 0, 19043}, // Windows 10 Version 21H1 (May 2021 Update) (21H1)
|
||||||
|
{10, 0, 19044}, // Windows 10 Version 21H2 (November 2021 Update) (21H2)
|
||||||
|
{10, 0, 22000}, // Windows 11 Version 21H2 (21H2)
|
||||||
|
};
|
||||||
|
static_assert((sizeof(WindowsVersions) / sizeof(WindowsVersions[0])) == (static_cast<int>(WindowsVersion::_11_21H2) + 1));
|
||||||
|
|
||||||
} // namespace Global
|
} // namespace Global
|
||||||
|
|
||||||
namespace FramelessHelper::Core
|
namespace FramelessHelper::Core
|
||||||
|
@ -380,5 +521,6 @@ FRAMELESSHELPER_CORE_API void initialize(const Global::Options options = {});
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global::UserSettings))
|
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber)
|
||||||
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global::SystemParameters))
|
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::UserSettings)
|
||||||
|
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::SystemParameters)
|
||||||
|
|
|
@ -58,14 +58,7 @@ FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter(
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isTitleBarColorized();
|
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isTitleBarColorized();
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8OrGreater();
|
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowsVersionOrGreater(const Global::WindowsVersion version);
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin8Point1OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1607OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1809OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_1903OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin10_2004OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWin11OrGreater();
|
|
||||||
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isDwmCompositionEnabled();
|
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isDwmCompositionEnabled();
|
||||||
FRAMELESSHELPER_CORE_API void triggerFrameChange(const WId windowId);
|
FRAMELESSHELPER_CORE_API void triggerFrameChange(const WId windowId);
|
||||||
FRAMELESSHELPER_CORE_API void updateWindowFrameMargins(const WId windowId, const bool reset);
|
FRAMELESSHELPER_CORE_API void updateWindowFrameMargins(const WId windowId, const bool reset);
|
||||||
|
|
|
@ -245,16 +245,16 @@ void FramelessHelperWin::addWindow(const UserSettings &settings, const SystemPar
|
||||||
}
|
}
|
||||||
Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true);
|
Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true);
|
||||||
Utils::updateWindowFrameMargins(windowId, false);
|
Utils::updateWindowFrameMargins(windowId, false);
|
||||||
if (Utils::isWin10_1607OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607)) {
|
||||||
const bool dark = Utils::shouldAppsUseDarkMode();
|
const bool dark = Utils::shouldAppsUseDarkMode();
|
||||||
if (!(settings.options & Option::DontTouchWindowFrameBorderColor)) {
|
if (!(settings.options & Option::DontTouchWindowFrameBorderColor)) {
|
||||||
Utils::updateWindowFrameBorderColor(windowId, dark);
|
Utils::updateWindowFrameBorderColor(windowId, dark);
|
||||||
}
|
}
|
||||||
if (Utils::isWin10_1809OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809)) {
|
||||||
if (settings.options & Option::SyncNativeControlsThemeWithSystem) {
|
if (settings.options & Option::SyncNativeControlsThemeWithSystem) {
|
||||||
Utils::updateGlobalWin32ControlsTheme(windowId, dark);
|
Utils::updateGlobalWin32ControlsTheme(windowId, dark);
|
||||||
}
|
}
|
||||||
if (Utils::isWin11OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)) {
|
||||||
if (settings.options & Option::MaximizeButtonDocking) {
|
if (settings.options & Option::MaximizeButtonDocking) {
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
SetLastError(ERROR_SUCCESS);
|
SetLastError(ERROR_SUCCESS);
|
||||||
|
@ -458,7 +458,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
// Due to ABM_GETAUTOHIDEBAREX only exists from Win8.1,
|
// Due to ABM_GETAUTOHIDEBAREX only exists from Win8.1,
|
||||||
// we have to use another way to judge this if we are
|
// we have to use another way to judge this if we are
|
||||||
// running on Windows 7 or Windows 8.
|
// running on Windows 7 or Windows 8.
|
||||||
if (Utils::isWin8Point1OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_8_1)) {
|
||||||
MONITORINFO monitorInfo;
|
MONITORINFO monitorInfo;
|
||||||
SecureZeroMemory(&monitorInfo, sizeof(monitorInfo));
|
SecureZeroMemory(&monitorInfo, sizeof(monitorInfo));
|
||||||
monitorInfo.cbSize = sizeof(monitorInfo);
|
monitorInfo.cbSize = sizeof(monitorInfo);
|
||||||
|
@ -821,7 +821,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
}
|
}
|
||||||
bool systemThemeChanged = ((uMsg == WM_THEMECHANGED) || (uMsg == WM_SYSCOLORCHANGE)
|
bool systemThemeChanged = ((uMsg == WM_THEMECHANGED) || (uMsg == WM_SYSCOLORCHANGE)
|
||||||
|| (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED));
|
|| (uMsg == WM_DWMCOLORIZATIONCOLORCHANGED));
|
||||||
if (Utils::isWin10_1607OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607)) {
|
||||||
if (uMsg == WM_SETTINGCHANGE) {
|
if (uMsg == WM_SETTINGCHANGE) {
|
||||||
if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast<LPCWSTR>(lParam))
|
if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast<LPCWSTR>(lParam))
|
||||||
.compare(qThemeSettingChangeEventName, Qt::CaseInsensitive) == 0)) {
|
.compare(qThemeSettingChangeEventName, Qt::CaseInsensitive) == 0)) {
|
||||||
|
@ -830,7 +830,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
if (!(data.settings.options & Option::DontTouchWindowFrameBorderColor)) {
|
if (!(data.settings.options & Option::DontTouchWindowFrameBorderColor)) {
|
||||||
Utils::updateWindowFrameBorderColor(windowId, dark);
|
Utils::updateWindowFrameBorderColor(windowId, dark);
|
||||||
}
|
}
|
||||||
if (Utils::isWin10_1809OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1809)) {
|
||||||
if (data.settings.options & Option::SyncNativeControlsThemeWithSystem) {
|
if (data.settings.options & Option::SyncNativeControlsThemeWithSystem) {
|
||||||
Utils::updateGlobalWin32ControlsTheme(windowId, dark);
|
Utils::updateGlobalWin32ControlsTheme(windowId, dark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -310,6 +310,8 @@ void FramelessHelper::Core::initialize(const Options options)
|
||||||
qRegisterMetaType<DwmColorizationArea>();
|
qRegisterMetaType<DwmColorizationArea>();
|
||||||
qRegisterMetaType<Anchor>();
|
qRegisterMetaType<Anchor>();
|
||||||
qRegisterMetaType<ButtonState>();
|
qRegisterMetaType<ButtonState>();
|
||||||
|
qRegisterMetaType<WindowsVersion>();
|
||||||
|
qRegisterMetaType<VersionNumber>();
|
||||||
qRegisterMetaType<UserSettings>();
|
qRegisterMetaType<UserSettings>();
|
||||||
qRegisterMetaType<SystemParameters>();
|
qRegisterMetaType<SystemParameters>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ static inline void
|
||||||
xcb_button_release_event_t xev;
|
xcb_button_release_event_t xev;
|
||||||
memset(&xev, 0, sizeof(xev));
|
memset(&xev, 0, sizeof(xev));
|
||||||
xev.response_type = XCB_BUTTON_RELEASE;
|
xev.response_type = XCB_BUTTON_RELEASE;
|
||||||
xev.time = XCB_CURRENT_TIME;
|
xev.time = QX11Info::appTime();
|
||||||
xev.root = rootWindow;
|
xev.root = rootWindow;
|
||||||
xev.root_x = globalPos.x();
|
xev.root_x = globalPos.x();
|
||||||
xev.root_y = globalPos.y();
|
xev.root_y = globalPos.y();
|
||||||
|
@ -135,7 +135,7 @@ static inline void
|
||||||
xev.event_x = localPos.x();
|
xev.event_x = localPos.x();
|
||||||
xev.event_y = localPos.y();
|
xev.event_y = localPos.y();
|
||||||
xev.same_screen = true;
|
xev.same_screen = true;
|
||||||
xcb_send_event(connection, false, rootWindow, XCB_EVENT_MASK_BUTTON_RELEASE,
|
xcb_send_event(connection, false, rootWindow, XCB_EVENT_MASK_STRUCTURE_NOTIFY,
|
||||||
reinterpret_cast<const char *>(&xev));
|
reinterpret_cast<const char *>(&xev));
|
||||||
xcb_flush(connection);
|
xcb_flush(connection);
|
||||||
}
|
}
|
||||||
|
@ -174,13 +174,26 @@ static inline void
|
||||||
xev.data.data32[3] = XCB_BUTTON_INDEX_1;
|
xev.data.data32[3] = XCB_BUTTON_INDEX_1;
|
||||||
// First we need to ungrab the pointer that may have been
|
// First we need to ungrab the pointer that may have been
|
||||||
// automatically grabbed by Qt on ButtonPressEvent.
|
// automatically grabbed by Qt on ButtonPressEvent.
|
||||||
xcb_ungrab_pointer(connection, XCB_CURRENT_TIME);
|
xcb_ungrab_pointer(connection, QX11Info::appTime());
|
||||||
xcb_send_event(connection, false, rootWindow,
|
xcb_send_event(connection, false, rootWindow,
|
||||||
(XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY),
|
(XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY),
|
||||||
reinterpret_cast<const char *>(&xev));
|
reinterpret_cast<const char *>(&xev));
|
||||||
xcb_flush(connection);
|
xcb_flush(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void sendMouseReleaseEvent(QWindow *window, const QPoint &globalPos)
|
||||||
|
{
|
||||||
|
Q_ASSERT(window);
|
||||||
|
if (!window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const qreal dpr = window->devicePixelRatio();
|
||||||
|
const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint();
|
||||||
|
const QPoint logicalLocalPos = window->mapFromGlobal(globalPos);
|
||||||
|
const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint();
|
||||||
|
emulateMouseButtonRelease(window->winId(), deviceGlobalPos, deviceLocalPos);
|
||||||
|
}
|
||||||
|
|
||||||
SystemTheme Utils::getSystemTheme()
|
SystemTheme Utils::getSystemTheme()
|
||||||
{
|
{
|
||||||
// ### TODO: how to detect high contrast mode on Linux?
|
// ### TODO: how to detect high contrast mode on Linux?
|
||||||
|
@ -193,17 +206,13 @@ void Utils::startSystemMove(QWindow *window, const QPoint &globalPos)
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const WId windowId = window->winId();
|
|
||||||
const qreal dpr = window->devicePixelRatio();
|
|
||||||
const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint();
|
|
||||||
const QPoint logicalLocalPos = window->mapFromGlobal(globalPos);
|
|
||||||
const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint();
|
|
||||||
// Before we start the dragging we need to tell Qt that the mouse is released.
|
// Before we start the dragging we need to tell Qt that the mouse is released.
|
||||||
emulateMouseButtonRelease(windowId, deviceGlobalPos, deviceLocalPos);
|
sendMouseReleaseEvent(window, globalPos);
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
window->startSystemMove();
|
window->startSystemMove();
|
||||||
#else
|
#else
|
||||||
doStartSystemMoveResize(windowId, deviceGlobalPos, _NET_WM_MOVERESIZE_MOVE);
|
const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * window->devicePixelRatio()).toPoint();
|
||||||
|
doStartSystemMoveResize(window->winId(), deviceGlobalPos, _NET_WM_MOVERESIZE_MOVE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,13 +225,8 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoi
|
||||||
if (edges == Qt::Edges{}) {
|
if (edges == Qt::Edges{}) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const WId windowId = window->winId();
|
|
||||||
const qreal dpr = window->devicePixelRatio();
|
|
||||||
const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * dpr).toPoint();
|
|
||||||
const QPoint logicalLocalPos = window->mapFromGlobal(globalPos);
|
|
||||||
const QPoint deviceLocalPos = QPointF(QPointF(logicalLocalPos) * dpr).toPoint();
|
|
||||||
// Before we start the resizing we need to tell Qt that the mouse is released.
|
// Before we start the resizing we need to tell Qt that the mouse is released.
|
||||||
emulateMouseButtonRelease(windowId, deviceGlobalPos, deviceLocalPos);
|
sendMouseReleaseEvent(window, globalPos);
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||||
window->startSystemResize(edges);
|
window->startSystemResize(edges);
|
||||||
#else
|
#else
|
||||||
|
@ -230,7 +234,8 @@ void Utils::startSystemResize(QWindow *window, const Qt::Edges edges, const QPoi
|
||||||
if (section < 0) {
|
if (section < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doStartSystemMoveResize(windowId, deviceGlobalPos, section);
|
const QPoint deviceGlobalPos = QPointF(QPointF(globalPos) * window->devicePixelRatio()).toPoint();
|
||||||
|
doStartSystemMoveResize(window->winId(), deviceGlobalPos, section);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,6 @@
|
||||||
#include <QtCore/qsettings.h>
|
#include <QtCore/qsettings.h>
|
||||||
#include <QtGui/qguiapplication.h>
|
#include <QtGui/qguiapplication.h>
|
||||||
#include <QtCore/private/qsystemlibrary_p.h>
|
#include <QtCore/private/qsystemlibrary_p.h>
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
# include <QtCore/qoperatingsystemversion.h>
|
|
||||||
#else
|
|
||||||
# include <QtCore/qsysinfo.h>
|
|
||||||
#endif
|
|
||||||
#include <QtGui/qpa/qplatformwindow.h>
|
#include <QtGui/qpa/qplatformwindow.h>
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
# include <QtGui/qpa/qplatformnativeinterface.h>
|
# include <QtGui/qpa/qplatformnativeinterface.h>
|
||||||
|
@ -130,8 +125,8 @@ FRAMELESSHELPER_STRING_CONSTANT(SetMenuDefaultItem)
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(HiliteMenuItem)
|
FRAMELESSHELPER_STRING_CONSTANT(HiliteMenuItem)
|
||||||
FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu)
|
FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu)
|
||||||
|
|
||||||
[[maybe_unused]] [[nodiscard]] static inline bool
|
[[nodiscard]] static inline bool
|
||||||
isWindowsVersionOrGreater(const DWORD dwMajor, const DWORD dwMinor, const DWORD dwBuild)
|
doCompareWindowsVersion(const DWORD dwMajor, const DWORD dwMinor, const DWORD dwBuild)
|
||||||
{
|
{
|
||||||
OSVERSIONINFOEXW osvi;
|
OSVERSIONINFOEXW osvi;
|
||||||
SecureZeroMemory(&osvi, sizeof(osvi));
|
SecureZeroMemory(&osvi, sizeof(osvi));
|
||||||
|
@ -263,7 +258,7 @@ FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu)
|
||||||
return titleBarHeight;
|
return titleBarHeight;
|
||||||
}
|
}
|
||||||
const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
|
const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
|
||||||
if (Utils::isWin11OrGreater()) {
|
if (Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)) {
|
||||||
if (maxOrFull) {
|
if (maxOrFull) {
|
||||||
return (titleBarHeight + frameSizeY);
|
return (titleBarHeight + frameSizeY);
|
||||||
}
|
}
|
||||||
|
@ -319,52 +314,16 @@ FRAMELESSHELPER_STRING_CONSTANT(TrackPopupMenu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::isWin8OrGreater()
|
bool Utils::isWindowsVersionOrGreater(const WindowsVersion version)
|
||||||
{
|
{
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
const VersionNumber ver = WindowsVersions[static_cast<int>(version)];
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8);
|
return doCompareWindowsVersion(ver.major, ver.minor, ver.patch);
|
||||||
#else
|
|
||||||
static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin8Point1OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8_1);
|
|
||||||
#else
|
|
||||||
static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS8_1);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin10OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10);
|
|
||||||
#else
|
|
||||||
static const bool result = (QSysInfo::WindowsVersion >= QSysInfo::WV_WINDOWS10);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin11OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11);
|
|
||||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 22000));
|
|
||||||
#else
|
|
||||||
static const bool result = isWindowsVersionOrGreater(10, 0, 22000);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::isDwmCompositionEnabled()
|
bool Utils::isDwmCompositionEnabled()
|
||||||
{
|
{
|
||||||
// DWM composition is always enabled and can't be disabled since Windows 8.
|
// DWM composition is always enabled and can't be disabled since Windows 8.
|
||||||
if (isWin8OrGreater()) {
|
if (isWindowsVersionOrGreater(WindowsVersion::_8)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const auto resultFromRegistry = []() -> bool {
|
const auto resultFromRegistry = []() -> bool {
|
||||||
|
@ -512,7 +471,7 @@ QColor Utils::getDwmColorizationColor()
|
||||||
DwmColorizationArea Utils::getDwmColorizationArea()
|
DwmColorizationArea Utils::getDwmColorizationArea()
|
||||||
{
|
{
|
||||||
// It's a Win10 only feature. (TO BE VERIFIED)
|
// It's a Win10 only feature. (TO BE VERIFIED)
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) {
|
||||||
return DwmColorizationArea::None_;
|
return DwmColorizationArea::None_;
|
||||||
}
|
}
|
||||||
const QWinRegistryKey themeRegistry(HKEY_CURRENT_USER, qPersonalizeRegistryKey);
|
const QWinRegistryKey themeRegistry(HKEY_CURRENT_USER, qPersonalizeRegistryKey);
|
||||||
|
@ -720,52 +679,6 @@ void Utils::syncWmPaintWithDwm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::isWin10_1607OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14393));
|
|
||||||
#else
|
|
||||||
static const bool result = isWindowsVersionOrGreater(10, 0, 14393);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin10_1809OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_1809);
|
|
||||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17763));
|
|
||||||
#else
|
|
||||||
static const bool result = isWindowsVersionOrGreater(10, 0, 17763);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin10_1903OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_1903);
|
|
||||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 18362));
|
|
||||||
#else
|
|
||||||
static const bool result = isWindowsVersionOrGreater(10, 0, 18362);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isWin10_2004OrGreater()
|
|
||||||
{
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 3, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10_2004);
|
|
||||||
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
|
||||||
static const bool result = (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 19041));
|
|
||||||
#else
|
|
||||||
static const bool result = isWindowsVersionOrGreater(10, 0, 19041);
|
|
||||||
#endif
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Utils::isHighContrastModeEnabled()
|
bool Utils::isHighContrastModeEnabled()
|
||||||
{
|
{
|
||||||
HIGHCONTRASTW hc;
|
HIGHCONTRASTW hc;
|
||||||
|
@ -925,7 +838,7 @@ quint32 Utils::getFrameBorderThickness(const WId windowId, const bool scaled)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// There's no window frame border before Windows 10.
|
// There's no window frame border before Windows 10.
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
static const auto pDwmGetWindowAttribute =
|
static const auto pDwmGetWindowAttribute =
|
||||||
|
@ -951,7 +864,7 @@ QColor Utils::getFrameBorderColor(const bool active)
|
||||||
{
|
{
|
||||||
// There's no window frame border before Windows 10.
|
// There's no window frame border before Windows 10.
|
||||||
// So we just return a default value which is based on most window managers.
|
// So we just return a default value which is based on most window managers.
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) {
|
||||||
return (active ? kDefaultBlackColor : kDefaultDarkGrayColor);
|
return (active ? kDefaultBlackColor : kDefaultDarkGrayColor);
|
||||||
}
|
}
|
||||||
const bool dark = shouldAppsUseDarkMode();
|
const bool dark = shouldAppsUseDarkMode();
|
||||||
|
@ -973,7 +886,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// There's no global dark theme before Win10 1607.
|
// There's no global dark theme before Win10 1607.
|
||||||
if (!isWin10_1607OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1607)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static const auto pDwmSetWindowAttribute =
|
static const auto pDwmSetWindowAttribute =
|
||||||
|
@ -983,7 +896,7 @@ void Utils::updateWindowFrameBorderColor(const WId windowId, const bool dark)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
const auto hwnd = reinterpret_cast<HWND>(windowId);
|
||||||
const DWORD mode = (isWin10_2004OrGreater() ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1);
|
const DWORD mode = (isWindowsVersionOrGreater(WindowsVersion::_10_2004) ? _DWMWA_USE_IMMERSIVE_DARK_MODE : _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1);
|
||||||
const BOOL value = (dark ? TRUE : FALSE);
|
const BOOL value = (dark ? TRUE : FALSE);
|
||||||
const HRESULT hr = pDwmSetWindowAttribute(hwnd, mode, &value, sizeof(value));
|
const HRESULT hr = pDwmSetWindowAttribute(hwnd, mode, &value, sizeof(value));
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
|
@ -1106,7 +1019,7 @@ bool Utils::isWindowFrameBorderVisible()
|
||||||
if (settings.value(kForceHideFrameBorderKeyPath, false).toBool()) {
|
if (settings.value(kForceHideFrameBorderKeyPath, false).toBool()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isWin10OrGreater();
|
return isWindowsVersionOrGreater(WindowsVersion::_10_1507);
|
||||||
}();
|
}();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -1114,7 +1027,7 @@ bool Utils::isWindowFrameBorderVisible()
|
||||||
bool Utils::isTitleBarColorized()
|
bool Utils::isTitleBarColorized()
|
||||||
{
|
{
|
||||||
// CHECK: is it supported on win7?
|
// CHECK: is it supported on win7?
|
||||||
if (!isWin10OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1507)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const DwmColorizationArea area = getDwmColorizationArea();
|
const DwmColorizationArea area = getDwmColorizationArea();
|
||||||
|
@ -1325,7 +1238,7 @@ SystemTheme Utils::getSystemTheme()
|
||||||
if (isHighContrastModeEnabled()) {
|
if (isHighContrastModeEnabled()) {
|
||||||
return SystemTheme::HighContrast;
|
return SystemTheme::HighContrast;
|
||||||
}
|
}
|
||||||
if (isWin10_1607OrGreater() && shouldAppsUseDarkMode()) {
|
if (isWindowsVersionOrGreater(WindowsVersion::_10_1607) && shouldAppsUseDarkMode()) {
|
||||||
return SystemTheme::Dark;
|
return SystemTheme::Dark;
|
||||||
}
|
}
|
||||||
return SystemTheme::Light;
|
return SystemTheme::Light;
|
||||||
|
@ -1338,7 +1251,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// There's no global dark theme for common Win32 controls before Win10 1809.
|
// There's no global dark theme for common Win32 controls before Win10 1809.
|
||||||
if (!isWin10_1809OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1809)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static const auto pSetWindowTheme =
|
static const auto pSetWindowTheme =
|
||||||
|
@ -1357,7 +1270,7 @@ void Utils::updateGlobalWin32ControlsTheme(const WId windowId, const bool dark)
|
||||||
bool Utils::shouldAppsUseDarkMode_windows()
|
bool Utils::shouldAppsUseDarkMode_windows()
|
||||||
{
|
{
|
||||||
// The global dark mode was first introduced in Windows 10 1607.
|
// The global dark mode was first introduced in Windows 10 1607.
|
||||||
if (!isWin10_1607OrGreater()) {
|
if (!isWindowsVersionOrGreater(WindowsVersion::_10_1607)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto resultFromRegistry = []() -> bool {
|
const auto resultFromRegistry = []() -> bool {
|
||||||
|
@ -1368,7 +1281,7 @@ bool Utils::shouldAppsUseDarkMode_windows()
|
||||||
static const auto pShouldAppsUseDarkMode =
|
static const auto pShouldAppsUseDarkMode =
|
||||||
reinterpret_cast<BOOL(WINAPI *)(VOID)>(
|
reinterpret_cast<BOOL(WINAPI *)(VOID)>(
|
||||||
QSystemLibrary::resolve(kuxtheme, MAKEINTRESOURCEA(132)));
|
QSystemLibrary::resolve(kuxtheme, MAKEINTRESOURCEA(132)));
|
||||||
if (pShouldAppsUseDarkMode && !isWin10_1903OrGreater()) {
|
if (pShouldAppsUseDarkMode && !isWindowsVersionOrGreater(WindowsVersion::_10_1903)) {
|
||||||
return (pShouldAppsUseDarkMode() != FALSE);
|
return (pShouldAppsUseDarkMode() != FALSE);
|
||||||
}
|
}
|
||||||
// Starting from Windows 10 1903, "ShouldAppsUseDarkMode()" always return "TRUE"
|
// Starting from Windows 10 1903, "ShouldAppsUseDarkMode()" always return "TRUE"
|
||||||
|
|
|
@ -56,7 +56,7 @@ qreal FramelessQuickUtils::titleBarHeight()
|
||||||
bool FramelessQuickUtils::frameBorderVisible()
|
bool FramelessQuickUtils::frameBorderVisible()
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater());
|
return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2));
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -641,7 +641,7 @@ bool FramelessQuickWindowPrivate::shouldIgnoreMouseEvents(const QPoint &pos) con
|
||||||
bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const
|
bool FramelessQuickWindowPrivate::shouldDrawFrameBorder() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater()
|
return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)
|
||||||
&& !(m_settings.options & Option::DontDrawTopWindowFrameBorder));
|
&& !(m_settings.options & Option::DontDrawTopWindowFrameBorder));
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -660,7 +660,7 @@ bool FramelessWidgetsHelper::isInTitleBarDraggableArea(const QPoint &pos) const
|
||||||
bool FramelessWidgetsHelper::shouldDrawFrameBorder() const
|
bool FramelessWidgetsHelper::shouldDrawFrameBorder() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
return (Utils::isWindowFrameBorderVisible() && !Utils::isWin11OrGreater()
|
return (Utils::isWindowFrameBorderVisible() && !Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2)
|
||||||
&& isNormal() && !(m_settings.options & Option::DontDrawTopWindowFrameBorder));
|
&& isNormal() && !(m_settings.options & Option::DontDrawTopWindowFrameBorder));
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue