forked from github_mirror/framelesshelper
win32: minor improvements
1. Fix build on 32bit platforms: the "Ptr" suffixed APIs not available on 32bit platforms 2. Reduce the confusion caused by the original "UseStandardWindowLayout" option 3. Minor tweaks of the quick implementation Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
be09197784
commit
eb1c6f4a62
|
@ -37,7 +37,7 @@ static const UserSettings settings =
|
||||||
/* startupPosition */ QPoint(),
|
/* startupPosition */ QPoint(),
|
||||||
/* startupSize */ QSize(),
|
/* startupSize */ QSize(),
|
||||||
/* startupState */ Qt::WindowNoState,
|
/* startupState */ Qt::WindowNoState,
|
||||||
/* options */ { Option::UseStandardWindowLayout },
|
/* options */ { Option::CreateStandardWindowLayout }, // Only needed by this demo application, you most probably don't need this option.
|
||||||
/* systemMenuOffset */ QPoint(),
|
/* systemMenuOffset */ QPoint(),
|
||||||
/* minimizeButton */ nullptr,
|
/* minimizeButton */ nullptr,
|
||||||
/* maximizeButton */ nullptr,
|
/* maximizeButton */ nullptr,
|
||||||
|
|
|
@ -157,6 +157,46 @@ using MONITOR_DPI_TYPE = enum MONITOR_DPI_TYPE
|
||||||
MDT_DEFAULT = MDT_EFFECTIVE_DPI
|
MDT_DEFAULT = MDT_EFFECTIVE_DPI
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if !(defined(WIN64) || defined(_WIN64))
|
||||||
|
EXTERN_C inline LONG_PTR WINAPI
|
||||||
|
GetWindowLongPtrA(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_In_ int nIndex
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return GetWindowLongA(hWnd, nIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXTERN_C inline LONG_PTR WINAPI
|
||||||
|
GetWindowLongPtrW(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_In_ int nIndex
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return GetWindowLongW(hWnd, nIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXTERN_C inline LONG_PTR WINAPI
|
||||||
|
SetWindowLongPtrA(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_In_ int nIndex,
|
||||||
|
_In_ LONG_PTR dwNewLong
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return SetWindowLongA(hWnd, nIndex, dwNewLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
EXTERN_C inline LONG_PTR WINAPI
|
||||||
|
SetWindowLongPtrW(
|
||||||
|
_In_ HWND hWnd,
|
||||||
|
_In_ int nIndex,
|
||||||
|
_In_ LONG_PTR dwNewLong
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return SetWindowLongW(hWnd, nIndex, dwNewLong);
|
||||||
|
}
|
||||||
|
#endif // !(defined(WIN64) || defined(_WIN64))
|
||||||
|
|
||||||
EXTERN_C MMRESULT WINAPI
|
EXTERN_C MMRESULT WINAPI
|
||||||
timeGetDevCaps(
|
timeGetDevCaps(
|
||||||
_Out_writes_bytes_(cbtc) LPTIMECAPS ptc,
|
_Out_writes_bytes_(cbtc) LPTIMECAPS ptc,
|
||||||
|
|
|
@ -125,7 +125,7 @@ using NATIVE_EVENT_RESULT_TYPE = long;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FRAMELESSHELPER_NAMESPACE
|
#ifndef FRAMELESSHELPER_NAMESPACE
|
||||||
# define FRAMELESSHELPER_NAMESPACE __wwx190_flh_ns
|
# define FRAMELESSHELPER_NAMESPACE wangwenx190::FramelessHelper
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FRAMELESSHELPER_BEGIN_NAMESPACE
|
#ifndef FRAMELESSHELPER_BEGIN_NAMESPACE
|
||||||
|
@ -193,7 +193,7 @@ enum class Option : int
|
||||||
EnableRoundedWindowCorners = 0x00000008, // Not implemented yet.
|
EnableRoundedWindowCorners = 0x00000008, // Not implemented yet.
|
||||||
TransparentWindowBackground = 0x00000010, // Not implemented yet.
|
TransparentWindowBackground = 0x00000010, // Not implemented yet.
|
||||||
MaximizeButtonDocking = 0x00000020, // Windows only, enable the window docking feature introduced in Windows 11.
|
MaximizeButtonDocking = 0x00000020, // Windows only, enable the window docking feature introduced in Windows 11.
|
||||||
UseStandardWindowLayout = 0x00000040, // The standard window layout is a titlebar always on top and fill the window width.
|
CreateStandardWindowLayout = 0x00000040, // Using this option will cause FramelessHelper create a homemade titlebar and a window layout to contain it. If your window has a layout already, the newly created layout will mess up your own layout.
|
||||||
BeCompatibleWithQtFramelessWindowHint = 0x00000080, // Windows only, make the code compatible with Qt::FramelessWindowHint. Don't use this option unless you really need that flag.
|
BeCompatibleWithQtFramelessWindowHint = 0x00000080, // Windows only, make the code compatible with Qt::FramelessWindowHint. Don't use this option unless you really need that flag.
|
||||||
DontTouchQtInternals = 0x00000100, // Windows only, don't modify Qt's internal data.
|
DontTouchQtInternals = 0x00000100, // Windows only, don't modify Qt's internal data.
|
||||||
DontTouchWindowFrameBorderColor = 0x00000200, // Windows only, don't change the window frame border color.
|
DontTouchWindowFrameBorderColor = 0x00000200, // Windows only, don't change the window frame border color.
|
||||||
|
|
|
@ -38,8 +38,24 @@
|
||||||
# define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, 1
|
# define QUICK_URI_SHORT FRAMELESSHELPER_QUICK_URI, 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef QUICK_URI_FULL
|
||||||
|
# define QUICK_URI_FULL QUICK_URI_SHORT, 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef QUICK_URI_EXPAND
|
#ifndef QUICK_URI_EXPAND
|
||||||
# define QUICK_URI_EXPAND(name) QUICK_URI_SHORT, 0, name
|
# define QUICK_URI_EXPAND(name) QUICK_URI_FULL, name
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef qmlRegisterAnonymousType2
|
||||||
|
# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
# define qmlRegisterAnonymousType2(Class, ...) qmlRegisterAnonymousType<Class, 254>(__VA_ARGS__)
|
||||||
|
# else
|
||||||
|
# define qmlRegisterAnonymousType2(Class, ...) qmlRegisterAnonymousType<Class>(__VA_ARGS__)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef qmlRegisgerFile
|
||||||
|
# define qmlRegisterFile(Name) qmlRegisterType(QML_URL_EXPAND(Name), QUICK_URI_EXPAND(Name))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The "Q_INIT_RESOURCE()" macro can't be used inside a namespace,
|
// The "Q_INIT_RESOURCE()" macro can't be used inside a namespace,
|
||||||
|
@ -64,6 +80,7 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
||||||
}
|
}
|
||||||
inited = true;
|
inited = true;
|
||||||
engine->addImageProvider(FRAMELESSHELPER_STRING_LITERAL("framelesshelper"), new FramelessHelperImageProvider);
|
engine->addImageProvider(FRAMELESSHELPER_STRING_LITERAL("framelesshelper"), new FramelessHelperImageProvider);
|
||||||
|
qmlRegisterModule(QUICK_URI_FULL);
|
||||||
qmlRegisterUncreatableMetaObject(Global::staticMetaObject, QUICK_URI_EXPAND("FramelessHelper"),
|
qmlRegisterUncreatableMetaObject(Global::staticMetaObject, QUICK_URI_EXPAND("FramelessHelper"),
|
||||||
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access its enums."));
|
FRAMELESSHELPER_STRING_LITERAL("The FramelessHelper namespace is not creatable, you can only use it to access its enums."));
|
||||||
qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"),
|
qmlRegisterSingletonType<FramelessQuickUtils>(QUICK_URI_EXPAND("FramelessUtils"),
|
||||||
|
@ -72,17 +89,14 @@ void FramelessHelper::Quick::registerTypes(QQmlEngine *engine)
|
||||||
Q_UNUSED(scriptEngine);
|
Q_UNUSED(scriptEngine);
|
||||||
return new FramelessQuickUtils;
|
return new FramelessQuickUtils;
|
||||||
});
|
});
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
qmlRegisterAnonymousType2(QWindow, QUICK_URI_SHORT);
|
||||||
qmlRegisterAnonymousType<QWindow, 254>(QUICK_URI_SHORT);
|
qmlRegisterAnonymousType2(QQuickWindow, QUICK_URI_SHORT);
|
||||||
#else
|
|
||||||
qmlRegisterAnonymousType<QWindow>(QUICK_URI_SHORT);
|
|
||||||
#endif
|
|
||||||
qmlRegisterType<FramelessQuickWindow>(QUICK_URI_EXPAND("FramelessWindow"));
|
qmlRegisterType<FramelessQuickWindow>(QUICK_URI_EXPAND("FramelessWindow"));
|
||||||
initResource();
|
initResource();
|
||||||
qmlRegisterType(QML_URL_EXPAND("MinimizeButton"), QUICK_URI_EXPAND("MinimizeButton"));
|
qmlRegisterFile("MinimizeButton");
|
||||||
qmlRegisterType(QML_URL_EXPAND("MaximizeButton"), QUICK_URI_EXPAND("MaximizeButton"));
|
qmlRegisterFile("MaximizeButton");
|
||||||
qmlRegisterType(QML_URL_EXPAND("CloseButton"), QUICK_URI_EXPAND("CloseButton"));
|
qmlRegisterFile("CloseButton");
|
||||||
qmlRegisterType(QML_URL_EXPAND("StandardTitleBar"), QUICK_URI_EXPAND("StandardTitleBar"));
|
qmlRegisterFile("StandardTitleBar");
|
||||||
}
|
}
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -127,7 +127,7 @@ void FramelessWidgetsHelper::setTitleBarWidget(QWidget *widget)
|
||||||
if (m_userTitleBarWidget == widget) {
|
if (m_userTitleBarWidget == widget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
if (m_systemTitleBarWidget && m_systemTitleBarWidget->isVisible()) {
|
if (m_systemTitleBarWidget && m_systemTitleBarWidget->isVisible()) {
|
||||||
m_mainLayout->removeWidget(m_systemTitleBarWidget);
|
m_mainLayout->removeWidget(m_systemTitleBarWidget);
|
||||||
m_systemTitleBarWidget->hide();
|
m_systemTitleBarWidget->hide();
|
||||||
|
@ -155,7 +155,7 @@ void FramelessWidgetsHelper::setContentWidget(QWidget *widget)
|
||||||
if (!widget) {
|
if (!widget) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!(m_settings.options & Option::UseStandardWindowLayout)) {
|
if (!(m_settings.options & Option::CreateStandardWindowLayout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_userContentWidget == widget) {
|
if (m_userContentWidget == widget) {
|
||||||
|
@ -226,7 +226,7 @@ void FramelessWidgetsHelper::changeEventHandler(QEvent *event)
|
||||||
if ((type != QEvent::WindowStateChange) && (type != QEvent::ActivationChange)) {
|
if ((type != QEvent::WindowStateChange) && (type != QEvent::ActivationChange)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bool standardLayout = (m_settings.options & Option::UseStandardWindowLayout);
|
const bool standardLayout = (m_settings.options & Option::CreateStandardWindowLayout);
|
||||||
if (type == QEvent::WindowStateChange) {
|
if (type == QEvent::WindowStateChange) {
|
||||||
if (standardLayout) {
|
if (standardLayout) {
|
||||||
if (isZoomed()) {
|
if (isZoomed()) {
|
||||||
|
@ -386,10 +386,10 @@ void FramelessWidgetsHelper::initialize()
|
||||||
m_params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool { return isInSystemButtons(pos, button); };
|
m_params.isInsideSystemButtons = [this](const QPoint &pos, SystemButtonType *button) -> bool { return isInSystemButtons(pos, button); };
|
||||||
m_params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); };
|
m_params.isInsideTitleBarDraggableArea = [this](const QPoint &pos) -> bool { return isInTitleBarDraggableArea(pos); };
|
||||||
m_params.getWindowDevicePixelRatio = [this]() -> qreal { return q->devicePixelRatioF(); };
|
m_params.getWindowDevicePixelRatio = [this]() -> qreal { return q->devicePixelRatioF(); };
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
if (q->inherits(QT_MAINWINDOW_CLASS_NAME)) {
|
if (q->inherits(QT_MAINWINDOW_CLASS_NAME)) {
|
||||||
m_settings.options &= ~Options(Option::UseStandardWindowLayout);
|
m_settings.options &= ~Options(Option::CreateStandardWindowLayout);
|
||||||
qWarning() << "\"Option::UseStandardWindowLayout\" is not compatible with QMainWindow and it's subclasses."
|
qWarning() << "\"Option::CreateStandardWindowLayout\" is not compatible with QMainWindow and it's subclasses."
|
||||||
" Enabling this option will mess up with your main window's layout.";
|
" Enabling this option will mess up with your main window's layout.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ void FramelessWidgetsHelper::initialize()
|
||||||
manager->addWindow(m_settings, m_params);
|
manager->addWindow(m_settings, m_params);
|
||||||
q->installEventFilter(this);
|
q->installEventFilter(this);
|
||||||
connect(manager, &FramelessWindowsManager::systemThemeChanged, this, [this](){
|
connect(manager, &FramelessWindowsManager::systemThemeChanged, this, [this](){
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
updateSystemTitleBarStyleSheet();
|
updateSystemTitleBarStyleSheet();
|
||||||
updateSystemButtonsIcon();
|
updateSystemButtonsIcon();
|
||||||
q->update();
|
q->update();
|
||||||
|
@ -417,7 +417,7 @@ void FramelessWidgetsHelper::initialize()
|
||||||
QMetaObject::invokeMethod(q, "zoomedChanged");
|
QMetaObject::invokeMethod(q, "zoomedChanged");
|
||||||
});
|
});
|
||||||
setupInitialUi();
|
setupInitialUi();
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
m_settings.minimizeButton = m_systemMinimizeButton;
|
m_settings.minimizeButton = m_systemMinimizeButton;
|
||||||
m_settings.maximizeButton = m_systemMaximizeButton;
|
m_settings.maximizeButton = m_systemMaximizeButton;
|
||||||
m_settings.closeButton = m_systemCloseButton;
|
m_settings.closeButton = m_systemCloseButton;
|
||||||
|
@ -426,7 +426,7 @@ void FramelessWidgetsHelper::initialize()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::createSystemTitleBar()
|
void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
{
|
{
|
||||||
if (!(m_settings.options & Option::UseStandardWindowLayout)) {
|
if (!(m_settings.options & Option::CreateStandardWindowLayout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_systemTitleBarWidget = new QWidget(q);
|
m_systemTitleBarWidget = new QWidget(q);
|
||||||
|
@ -469,7 +469,7 @@ void FramelessWidgetsHelper::createSystemTitleBar()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::createUserContentContainer()
|
void FramelessWidgetsHelper::createUserContentContainer()
|
||||||
{
|
{
|
||||||
if (!(m_settings.options & Option::UseStandardWindowLayout)) {
|
if (!(m_settings.options & Option::CreateStandardWindowLayout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_userContentContainerWidget = new QWidget(q);
|
m_userContentContainerWidget = new QWidget(q);
|
||||||
|
@ -482,7 +482,7 @@ void FramelessWidgetsHelper::createUserContentContainer()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::setupInitialUi()
|
void FramelessWidgetsHelper::setupInitialUi()
|
||||||
{
|
{
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
createSystemTitleBar();
|
createSystemTitleBar();
|
||||||
createUserContentContainer();
|
createUserContentContainer();
|
||||||
m_mainLayout = new QVBoxLayout(q);
|
m_mainLayout = new QVBoxLayout(q);
|
||||||
|
@ -555,7 +555,7 @@ bool FramelessWidgetsHelper::isInTitleBarDraggableArea(const QPoint &pos) const
|
||||||
}
|
}
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
if (m_settings.options & Option::UseStandardWindowLayout) {
|
if (m_settings.options & Option::CreateStandardWindowLayout) {
|
||||||
QRegion region = mapWidgetGeometryToScene(m_systemTitleBarWidget);
|
QRegion region = mapWidgetGeometryToScene(m_systemTitleBarWidget);
|
||||||
region -= mapWidgetGeometryToScene(m_systemMinimizeButton);
|
region -= mapWidgetGeometryToScene(m_systemMinimizeButton);
|
||||||
region -= mapWidgetGeometryToScene(m_systemMaximizeButton);
|
region -= mapWidgetGeometryToScene(m_systemMaximizeButton);
|
||||||
|
@ -595,7 +595,7 @@ void FramelessWidgetsHelper::updateContentsMargins()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
||||||
{
|
{
|
||||||
if (!(m_settings.options & Option::UseStandardWindowLayout)) {
|
if (!(m_settings.options & Option::CreateStandardWindowLayout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bool active = q->isActiveWindow();
|
const bool active = q->isActiveWindow();
|
||||||
|
@ -630,7 +630,7 @@ void FramelessWidgetsHelper::updateSystemTitleBarStyleSheet()
|
||||||
|
|
||||||
void FramelessWidgetsHelper::updateSystemButtonsIcon()
|
void FramelessWidgetsHelper::updateSystemButtonsIcon()
|
||||||
{
|
{
|
||||||
if (!(m_settings.options & Option::UseStandardWindowLayout)) {
|
if (!(m_settings.options & Option::CreateStandardWindowLayout)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const SystemTheme theme = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) ? SystemTheme::Dark : SystemTheme::Light);
|
const SystemTheme theme = ((Utils::shouldAppsUseDarkMode() || Utils::isTitleBarColorized()) ? SystemTheme::Dark : SystemTheme::Light);
|
||||||
|
|
Loading…
Reference in New Issue