diff --git a/README.md b/README.md index da15a11..6cb855b 100644 --- a/README.md +++ b/README.md @@ -266,7 +266,7 @@ Please refer to the demo projects to see more detailed usages: [examples](./exam - Change your system theme to "Basic" (in contrary to "Windows Aero"). - If you have multiple graphics cards, try to use another one instead. - Upgrade your operating system to at least Windows 11. - - Remove the `WS_THICKFRAME` and `WS_OVERLAPPED` styles from your window (doing so will break FramelessHelper's functionalities). + - Remove the `WS_THICKFRAME` and `WS_OVERLAPPED` styles from your window, and maybe also add the `WS_POPUP` style at the same time (doing so will break FramelessHelper's functionalities). - Force your application use the ANGLE backend instead of the Desktop OpenGL. - Force your application use pure software rendering instead of rendering through OpenGL. - Or just don't use OpenGL at all, try to use Direct3D/Vulkan/Metal instead. diff --git a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h index ed02394..7b21b66 100644 --- a/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h +++ b/include/FramelessHelper/Quick/private/quickstandardsystembutton_p.h @@ -64,6 +64,7 @@ private: QScopedPointer m_backgroundItem; QuickGlobal::SystemButtonType m_buttonType = QuickGlobal::SystemButtonType::Unknown; QMetaObject::Connection m_windowActiveConnection = {}; + bool m_settingIconCode = false; }; FRAMELESSHELPER_END_NAMESPACE diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp index e131932..8861072 100644 --- a/src/core/framelessmanager.cpp +++ b/src/core/framelessmanager.cpp @@ -71,7 +71,7 @@ FRAMELESSHELPER_BYTEARRAY_CONSTANT2(ValueOne, "1") FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Segoe Fluent Icons.ttf") FRAMELESSHELPER_STRING_CONSTANT2(IconFontName, "Segoe Fluent Icons") -static constexpr const int kIconFontPointSize = 7; +static constexpr const int kIconFontPointSize = 8; FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q) { diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index fb1f489..77a7597 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -580,6 +580,7 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel if (!windowId || !isWindowFixedSize) { return; } + const auto hWnd = reinterpret_cast(windowId); const HMENU hMenu = GetSystemMenu(hWnd, FALSE); if (!hMenu) { @@ -588,11 +589,13 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel // as an error so just ignore it and return early. return; } + + // Tweak the menu items according to the current window status. const bool maxOrFull = (IsMaximized(hWnd) || isFullScreen(windowId)); const bool fixedSize = isWindowFixedSize(); EnableMenuItem(hMenu, SC_RESTORE, (MF_BYCOMMAND | ((maxOrFull && !fixedSize) ? MFS_ENABLED : MFS_DISABLED))); // The first menu item should be selected by default if the menu is brought - // by keyboard. I don't know how to pre-select a menu item but it seems + // up by keyboard. I don't know how to pre-select a menu item but it seems // highlight can do the job. However, there's an annoying issue if we do // this manually: the highlighted menu item is really only highlighted, // not selected, so even if the mouse cursor hovers on other menu items @@ -606,16 +609,21 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel EnableMenuItem(hMenu, SC_MINIMIZE, (MF_BYCOMMAND | MFS_ENABLED)); EnableMenuItem(hMenu, SC_MAXIMIZE, (MF_BYCOMMAND | ((!maxOrFull && !fixedSize) ? MFS_ENABLED : MFS_DISABLED))); EnableMenuItem(hMenu, SC_CLOSE, (MF_BYCOMMAND | MFS_ENABLED)); + // The default menu item will appear in bold font. There can only be one default // menu item per menu at most. Set the item ID to "UINT_MAX" (or simply "-1") // can clear the default item for the given menu. SetMenuDefaultItem(hMenu, SC_CLOSE, FALSE); - const auto result = TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() + + // Popup the system menu at the required position. + const int result = TrackPopupMenu(hMenu, (TPM_RETURNCMD | (QGuiApplication::isRightToLeft() ? TPM_RIGHTALIGN : TPM_LEFTALIGN)), pos.x(), pos.y(), 0, hWnd, nullptr); - // The user canceled the menu, no need to continue. if (result == 0) { + // The user canceled the menu, no need to continue. return; } + + // Send the command that the user choses to the corresponding window. if (PostMessageW(hWnd, WM_SYSCOMMAND, result, 0) == FALSE) { qWarning() << getSystemErrorMessage(kPostMessageW); } diff --git a/src/quick/quickstandardsystembutton.cpp b/src/quick/quickstandardsystembutton.cpp index 773b296..87d7e99 100644 --- a/src/quick/quickstandardsystembutton.cpp +++ b/src/quick/quickstandardsystembutton.cpp @@ -59,7 +59,9 @@ void QuickStandardSystemButton::setButtonType(const QuickGlobal::SystemButtonTyp return; } m_buttonType = type; + m_settingIconCode = true; updateForeground(); + m_settingIconCode = false; } void QuickStandardSystemButton::updateForeground() @@ -67,10 +69,12 @@ void QuickStandardSystemButton::updateForeground() if (m_buttonType == QuickGlobal::SystemButtonType::Unknown) { return; } - const QString iconCode = Utils::getSystemButtonIconCode( - FRAMELESSHELPER_ENUM_QUICK_TO_CORE(SystemButtonType, m_buttonType)); - if (m_contentItem->text() != iconCode) { - m_contentItem->setText(iconCode); + if (m_settingIconCode) { + const QString iconCode = Utils::getSystemButtonIconCode( + FRAMELESSHELPER_ENUM_QUICK_TO_CORE(SystemButtonType, m_buttonType)); + if (m_contentItem->text() != iconCode) { + m_contentItem->setText(iconCode); + } } const QColor iconColor = [this]() -> QColor { const bool active = [this]() -> bool {