From a0c825930e0d758ec4477e43497e476168f3730f Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Fri, 24 Feb 2023 15:40:08 +0800 Subject: [PATCH] win: allow user disable specific system menu items Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- .../Core/framelesshelpercore_global.h | 6 ++++++ src/core/utils_win.cpp | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/FramelessHelper/Core/framelesshelpercore_global.h b/include/FramelessHelper/Core/framelesshelpercore_global.h index e5ac20e..25fba39 100644 --- a/include/FramelessHelper/Core/framelesshelpercore_global.h +++ b/include/FramelessHelper/Core/framelesshelpercore_global.h @@ -252,6 +252,12 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_CORE_API) = FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_DONT_OVERRIDE_CURSOR"); [[maybe_unused]] inline const QByteArray kDontToggleMaximizeVar = FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_DONT_TOGGLE_MAXIMIZE"); +[[maybe_unused]] inline const QByteArray kSysMenuDisableMinimizeVar + = FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_SYSTEM_MENU_DISABLE_MINIMIZE"); +[[maybe_unused]] inline const QByteArray kSysMenuDisableMaximizeVar + = FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_SYSTEM_MENU_DISABLE_MAXIMIZE"); +[[maybe_unused]] inline const QByteArray kSysMenuDisableRestoreVar + = FRAMELESSHELPER_BYTEARRAY_LITERAL("FRAMELESSHELPER_SYSTEM_MENU_DISABLE_RESTORE"); enum class Option { diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 5f58860..26da6c9 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -781,10 +781,13 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel return; } - // Tweak the menu items according to the current window status. + // Tweak the menu items according to the current window status and user settings. + const bool disableRestore = params->getProperty(kSysMenuDisableRestoreVar, false).toBool(); + const bool disableMinimize = params->getProperty(kSysMenuDisableMinimizeVar, false).toBool(); + const bool disableMaximize = params->getProperty(kSysMenuDisableMaximizeVar, false).toBool(); const bool maxOrFull = (IsMaximized(hWnd) || isFullScreen(windowId)); const bool fixedSize = params->isWindowFixedSize(); - EnableMenuItem(hMenu, SC_RESTORE, (MF_BYCOMMAND | ((maxOrFull && !fixedSize) ? MFS_ENABLED : MFS_DISABLED))); + EnableMenuItem(hMenu, SC_RESTORE, (MF_BYCOMMAND | ((maxOrFull && !fixedSize && !disableRestore) ? MFS_ENABLED : MFS_DISABLED))); // The first menu item should be selected by default if the menu is brought // 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 @@ -796,9 +799,9 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel // the menu look kind of weird. Currently I don't know how to fix this issue. HiliteMenuItem(hWnd, hMenu, SC_RESTORE, (MF_BYCOMMAND | (selectFirstEntry ? MFS_HILITE : MFS_UNHILITE))); EnableMenuItem(hMenu, SC_MOVE, (MF_BYCOMMAND | (!maxOrFull ? MFS_ENABLED : MFS_DISABLED))); - EnableMenuItem(hMenu, SC_SIZE, (MF_BYCOMMAND | ((!maxOrFull && !fixedSize) ? MFS_ENABLED : MFS_DISABLED))); - EnableMenuItem(hMenu, SC_MINIMIZE, (MF_BYCOMMAND | MFS_ENABLED)); - EnableMenuItem(hMenu, SC_MAXIMIZE, (MF_BYCOMMAND | ((!maxOrFull && !fixedSize) ? MFS_ENABLED : MFS_DISABLED))); + EnableMenuItem(hMenu, SC_SIZE, (MF_BYCOMMAND | ((!maxOrFull && !fixedSize && !(disableMinimize || disableMaximize)) ? MFS_ENABLED : MFS_DISABLED))); + EnableMenuItem(hMenu, SC_MINIMIZE, (MF_BYCOMMAND | (disableMinimize ? MFS_DISABLED : MFS_ENABLED))); + EnableMenuItem(hMenu, SC_MAXIMIZE, (MF_BYCOMMAND | ((!maxOrFull && !fixedSize && !disableMaximize) ? 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