diff --git a/src/core/framelesshelpercore.qrc b/src/core/framelesshelpercore.qrc
index 3cd9702..ef68a8d 100644
--- a/src/core/framelesshelpercore.qrc
+++ b/src/core/framelesshelpercore.qrc
@@ -1,5 +1,7 @@
resources/fonts/Segoe Fluent Icons.ttf
+ resources/fonts/Segoe MDL2 Assets.ttf
+ resources/fonts/Micon.ttf
diff --git a/src/core/framelessmanager.cpp b/src/core/framelessmanager.cpp
index d7a803c..58d7d5f 100644
--- a/src/core/framelessmanager.cpp
+++ b/src/core/framelessmanager.cpp
@@ -24,8 +24,8 @@
#include "framelessmanager.h"
#include "framelessmanager_p.h"
-#include
#include
+#include
#include
#include
#include
@@ -59,10 +59,41 @@ Q_GLOBAL_STATIC(FramelessManagerHelper, g_helper)
Q_GLOBAL_STATIC(FramelessManager, g_manager)
-FRAMELESSHELPER_STRING_CONSTANT2(IconFontFilePath, ":/org.wangwenx190.FramelessHelper/resources/fonts/Segoe Fluent Icons.ttf")
-FRAMELESSHELPER_STRING_CONSTANT2(IconFontName, "Segoe Fluent Icons")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontResourcePrefix, ":/org.wangwenx190.FramelessHelper/resources/fonts/")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_win11, "Segoe Fluent Icons.ttf")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_win, "Segoe MDL2 Assets.ttf")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFileName_unix, "Micon.ttf")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win11, "Segoe Fluent Icons")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_win, "Segoe MDL2 Assets")
+FRAMELESSHELPER_STRING_CONSTANT2(IconFontFamilyName_unix, "micon_nb")
static constexpr const int kIconFontPointSize = 8;
+[[nodiscard]] static inline QString iconFontFilePath()
+{
+ static const QString result = []() -> QString {
+#ifdef Q_OS_WINDOWS
+ static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
+ return (kIconFontResourcePrefix + (isWin11OrGreater ? kIconFontFileName_win11 : kIconFontFileName_win));
+#else
+ return (kIconFontResourcePrefix + kIconFontFileName_unix);
+#endif
+ }();
+ return result;
+}
+
+[[nodiscard]] static inline QString iconFontFamilyName()
+{
+ static const QString result = []() -> QString {
+#ifdef Q_OS_WINDOWS
+ static const bool isWin11OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_11_21H2);
+ return (isWin11OrGreater ? kIconFontFamilyName_win11 : kIconFontFamilyName_win);
+#else
+ return kIconFontFamilyName_unix;
+#endif
+ }();
+ return result;
+}
+
FramelessManagerPrivate::FramelessManagerPrivate(FramelessManager *q) : QObject(q)
{
Q_ASSERT(q);
@@ -101,8 +132,11 @@ void FramelessManagerPrivate::initializeIconFont()
}
inited = true;
initResource();
- if (QFontDatabase::addApplicationFont(kIconFontFilePath) < 0) {
- qWarning() << "Failed to load icon font:" << kIconFontFilePath;
+ const int id = QFontDatabase::addApplicationFont(iconFontFilePath());
+ if (id < 0) {
+ qWarning() << "Failed to load icon font:" << iconFontFilePath();
+ } else {
+ qDebug() << "Successfully registered icon font:" << QFontDatabase::applicationFontFamilies(id);
}
}
@@ -110,7 +144,7 @@ QFont FramelessManagerPrivate::getIconFont()
{
static const QFont font = []() -> QFont {
QFont f = {};
- f.setFamily(kIconFontName);
+ f.setFamily(iconFontFamilyName());
f.setPointSize(kIconFontPointSize);
return f;
}();
diff --git a/src/core/resources/fonts/Micon.ttf b/src/core/resources/fonts/Micon.ttf
new file mode 100644
index 0000000..e4ff6aa
Binary files /dev/null and b/src/core/resources/fonts/Micon.ttf differ
diff --git a/src/core/resources/fonts/Segoe MDL2 Assets.ttf b/src/core/resources/fonts/Segoe MDL2 Assets.ttf
new file mode 100644
index 0000000..066f108
Binary files /dev/null and b/src/core/resources/fonts/Segoe MDL2 Assets.ttf differ
diff --git a/src/core/utils.cpp b/src/core/utils.cpp
index a740f3c..5faff8b 100644
--- a/src/core/utils.cpp
+++ b/src/core/utils.cpp
@@ -23,6 +23,7 @@
*/
#include "utils.h"
+#include
#include
#include
#include
@@ -35,12 +36,21 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global;
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeWindowIcon, "\ue756")
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeHelpIcon, "\ue897")
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeMinimizeIcon, "\ue921")
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeMaximizeIcon, "\ue922")
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeRestoreIcon, "\ue923")
-FRAMELESSHELPER_STRING_CONSTANT2(ChromeCloseIcon, "\ue8bb")
+struct FONT_ICON
+{
+ quint32 win = 0;
+ quint32 unix = 0;
+};
+
+static const QHash g_fontIconsTable = {
+ {static_cast(SystemButtonType::Unknown), {0x0000, 0x0000}},
+ {static_cast(SystemButtonType::WindowIcon), {0xE756, 0xEB06}},
+ {static_cast(SystemButtonType::Help), {0xE897, 0xEC04}},
+ {static_cast(SystemButtonType::Minimize), {0xE921, 0xEAE0}},
+ {static_cast(SystemButtonType::Maximize), {0xE922, 0xEADE}},
+ {static_cast(SystemButtonType::Restore), {0xE923, 0xEAE2}},
+ {static_cast(SystemButtonType::Close), {0xE8BB, 0xEADA}}
+};
Qt::CursorShape Utils::calculateCursorShape(const QWindow *window, const QPoint &pos)
{
@@ -113,24 +123,16 @@ Qt::Edges Utils::calculateWindowEdges(const QWindow *window, const QPoint &pos)
QString Utils::getSystemButtonIconCode(const SystemButtonType button)
{
- switch (button) {
- case SystemButtonType::Unknown:
- Q_ASSERT(false);
- break;
- case SystemButtonType::WindowIcon:
- return kChromeWindowIcon;
- case SystemButtonType::Help:
- return kChromeHelpIcon;
- case SystemButtonType::Minimize:
- return kChromeMinimizeIcon;
- case SystemButtonType::Maximize:
- return kChromeMaximizeIcon;
- case SystemButtonType::Restore:
- return kChromeRestoreIcon;
- case SystemButtonType::Close:
- return kChromeCloseIcon;
+ if (!g_fontIconsTable.contains(static_cast(button))) {
+ qWarning() << "FIXME: Add FONT_ICON value for button" << button;
+ return {};
}
- return {};
+ const FONT_ICON icon = g_fontIconsTable.value(static_cast(button));
+#ifdef Q_OS_WINDOWS
+ return QChar(icon.win);
+#else
+ return QChar(icon.unix);
+#endif
}
QWindow *Utils::findWindow(const WId windowId)
diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp
index 43b7c4d..12c6503 100644
--- a/src/core/utils_win.cpp
+++ b/src/core/utils_win.cpp
@@ -905,15 +905,16 @@ bool Utils::isHighContrastModeEnabled()
quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
{
- const HMONITOR monitor = []() -> HMONITOR {
+ const auto getPrimaryMonitor = []() -> HMONITOR {
const HWND window = ensureDummyWindow();
if (window) {
return MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
}
static constexpr const int kTaskBarSize = 100;
return MonitorFromPoint(POINT{kTaskBarSize, kTaskBarSize}, MONITOR_DEFAULTTOPRIMARY);
- }();
+ };
if (API_SHCORE_AVAILABLE(GetDpiForMonitor)) {
+ const HMONITOR monitor = getPrimaryMonitor();
if (monitor) {
UINT dpiX = 0, dpiY = 0;
const HRESULT hr = API_CALL_FUNCTION(GetDpiForMonitor, monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
@@ -927,6 +928,7 @@ quint32 Utils::getPrimaryScreenDpi(const bool horizontal)
}
}
if (API_SHCORE_AVAILABLE(GetScaleFactorForMonitor)) {
+ const HMONITOR monitor = getPrimaryMonitor();
if (monitor) {
DEVICE_SCALE_FACTOR factor = DEVICE_SCALE_FACTOR_INVALID;
const HRESULT hr = API_CALL_FUNCTION(GetScaleFactorForMonitor, monitor, &factor);
@@ -1020,34 +1022,6 @@ quint32 Utils::getWindowDpi(const WId windowId, const bool horizontal)
qWarning() << getSystemErrorMessage(kGetDpiForSystem);
}
}
- if (API_SHCORE_AVAILABLE(GetDpiForMonitor)) {
- const HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
- if (monitor) {
- UINT dpiX = 0, dpiY = 0;
- const HRESULT hr = API_CALL_FUNCTION(GetDpiForMonitor, monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY);
- if (SUCCEEDED(hr) && (dpiX > 0) && (dpiY > 0)) {
- return (horizontal ? dpiX : dpiY);
- } else {
- qWarning() << __getSystemErrorMessage(kGetDpiForMonitor, hr);
- }
- } else {
- qWarning() << getSystemErrorMessage(kMonitorFromWindow);
- }
- }
- if (API_SHCORE_AVAILABLE(GetScaleFactorForMonitor)) {
- const HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
- if (monitor) {
- DEVICE_SCALE_FACTOR factor = DEVICE_SCALE_FACTOR_INVALID;
- const HRESULT hr = API_CALL_FUNCTION(GetScaleFactorForMonitor, monitor, &factor);
- if (SUCCEEDED(hr) && (factor != DEVICE_SCALE_FACTOR_INVALID)) {
- return quint32(qRound(qreal(USER_DEFAULT_SCREEN_DPI) * qreal(factor) / qreal(100)));
- } else {
- qWarning() << __getSystemErrorMessage(kGetScaleFactorForMonitor, hr);
- }
- } else {
- qWarning() << getSystemErrorMessage(kMonitorFromWindow);
- }
- }
return getPrimaryScreenDpi(horizontal);
}