minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-06-24 21:38:26 +08:00
parent ffa9bc912b
commit 75f19218c6
5 changed files with 22 additions and 9 deletions

View File

@ -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.

View File

@ -64,6 +64,7 @@ private:
QScopedPointer<QQuickRectangle> m_backgroundItem;
QuickGlobal::SystemButtonType m_buttonType = QuickGlobal::SystemButtonType::Unknown;
QMetaObject::Connection m_windowActiveConnection = {};
bool m_settingIconCode = false;
};
FRAMELESSHELPER_END_NAMESPACE

View File

@ -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)
{

View File

@ -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<HWND>(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);
}

View File

@ -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,11 +69,13 @@ void QuickStandardSystemButton::updateForeground()
if (m_buttonType == QuickGlobal::SystemButtonType::Unknown) {
return;
}
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 {
const QQuickWindow * const w = window();