Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
minor tweaks
Browse files Browse the repository at this point in the history
Signed-off-by: Yuhang Zhao <[email protected]>
  • Loading branch information
wangwenx190 committed Jun 24, 2022
1 parent ffa9bc9 commit 75f1921
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Q_SLOTS:
QScopedPointer<QQuickRectangle> m_backgroundItem;
QuickGlobal::SystemButtonType m_buttonType = QuickGlobal::SystemButtonType::Unknown;
QMetaObject::Connection m_windowActiveConnection = {};
bool m_settingIconCode = false;
};

FRAMELESSHELPER_END_NAMESPACE
Expand Down
2 changes: 1 addition & 1 deletion src/core/framelessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 11 additions & 3 deletions src/core/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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);
}
Expand Down
12 changes: 8 additions & 4 deletions src/quick/quickstandardsystembutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ void QuickStandardSystemButton::setButtonType(const QuickGlobal::SystemButtonTyp
return;
}
m_buttonType = type;
m_settingIconCode = true;
updateForeground();
m_settingIconCode = false;
}

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 {
Expand Down

0 comments on commit 75f1921

Please sign in to comment.