general refactor, remove useless code

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2023-02-05 14:01:46 +08:00
parent 3d37d87c81
commit 14ccc990cf
66 changed files with 224 additions and 497 deletions

View File

@ -24,7 +24,6 @@
#include <QtWidgets/qapplication.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <clocale>
#include "dialog.h"
#include "../shared/log.h"
@ -32,8 +31,6 @@ FRAMELESSHELPER_USE_NAMESPACE
int main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "en_US.UTF-8");
Log::setup(FRAMELESSHELPER_STRING_LITERAL("dialog"));
// Not necessary, but better call this function, before the construction

View File

@ -24,7 +24,6 @@
#include <QtWidgets/qapplication.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <clocale>
#include "mainwindow.h"
#include "../shared/log.h"
@ -32,8 +31,6 @@ FRAMELESSHELPER_USE_NAMESPACE
int main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "en_US.UTF-8");
Log::setup(FRAMELESSHELPER_STRING_LITERAL("mainwindow"));
// Not necessary, but better call this function, before the construction

View File

@ -32,7 +32,6 @@
#include <QtQuick/qquickwindow.h>
#include <FramelessHelper/Quick/framelessquickmodule.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <clocale>
#include "quicksettings.h"
#if QMLTC_ENABLED
# include <homepage.h>
@ -51,8 +50,6 @@ static constexpr const bool IS_MACOS_HOST =
int main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "en_US.UTF-8");
Log::setup(FRAMELESSHELPER_STRING_LITERAL("quick"));
// Not necessary, but better call this function, before the construction
@ -103,10 +100,12 @@ int main(int argc, char *argv[])
}());
}
#if 0
// Enable some helpful debugging messages.
if (!qEnvironmentVariableIsSet("QML_IMPORT_TRACE")) {
qputenv("QML_IMPORT_TRACE", FRAMELESSHELPER_BYTEARRAY_LITERAL("1"));
}
#endif
const auto engine = std::make_unique<QQmlApplicationEngine>();

View File

@ -24,7 +24,6 @@
#include <QtWidgets/qapplication.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <clocale>
#include "widget.h"
#include "../shared/log.h"
@ -32,8 +31,6 @@ FRAMELESSHELPER_USE_NAMESPACE
int main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "en_US.UTF-8");
Log::setup(FRAMELESSHELPER_STRING_LITERAL("widget"));
// Not necessary, but better call this function, before the construction

View File

@ -123,5 +123,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalette))

View File

@ -28,6 +28,8 @@
FRAMELESSHELPER_BEGIN_NAMESPACE
struct SystemParameters;
class FRAMELESSHELPER_CORE_API FramelessHelperQt : public QObject
{
Q_OBJECT
@ -37,7 +39,7 @@ public:
explicit FramelessHelperQt(QObject *parent = nullptr);
~FramelessHelperQt() override;
static void addWindow(const Global::SystemParameters &params);
static void addWindow(const SystemParameters *params);
static void removeWindow(const WId windowId);
protected:
@ -45,5 +47,3 @@ protected:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperQt))

View File

@ -29,6 +29,8 @@
FRAMELESSHELPER_BEGIN_NAMESPACE
struct SystemParameters;
class FRAMELESSHELPER_CORE_API FramelessHelperWin : public QAbstractNativeEventFilter
{
Q_DISABLE_COPY_MOVE(FramelessHelperWin)
@ -37,12 +39,10 @@ public:
explicit FramelessHelperWin();
~FramelessHelperWin() override;
static void addWindow(const Global::SystemParameters &params);
static void addWindow(const SystemParameters *params);
static void removeWindow(const WId windowId);
Q_NODISCARD bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessHelperWin))

View File

@ -409,7 +409,7 @@ using WINDOWCOMPOSITIONATTRIBDATA = struct WINDOWCOMPOSITIONATTRIBDATA
{
WINDOWCOMPOSITIONATTRIB Attrib;
PVOID pvData;
DWORD cbData;
SIZE_T cbData;
};
using PWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA *;

View File

@ -37,7 +37,6 @@
#include <memory>
QT_BEGIN_NAMESPACE
class QScreen;
class QEvent;
class QEnterEvent;
QT_END_NAMESPACE
@ -45,16 +44,16 @@ QT_END_NAMESPACE
#ifndef FRAMELESSHELPER_CORE_API
# ifdef FRAMELESSHELPER_CORE_STATIC
# define FRAMELESSHELPER_CORE_API
# else // FRAMELESSHELPER_CORE_STATIC
# else // !FRAMELESSHELPER_CORE_STATIC
# ifdef FRAMELESSHELPER_CORE_LIBRARY
# define FRAMELESSHELPER_CORE_API Q_DECL_EXPORT
# else // FRAMELESSHELPER_CORE_LIBRARY
# else // !FRAMELESSHELPER_CORE_LIBRARY
# define FRAMELESSHELPER_CORE_API Q_DECL_IMPORT
# endif // FRAMELESSHELPER_CORE_LIBRARY
# endif // FRAMELESSHELPER_CORE_STATIC
#endif
#endif // FRAMELESSHELPER_CORE_API
#if defined(Q_OS_WIN) && !defined(Q_OS_WINDOWS)
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINDOWS))
# define Q_OS_WINDOWS // Since 5.14
#endif
@ -78,7 +77,7 @@ QT_END_NAMESPACE
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
# define Q_NODISCARD [[nodiscard]]
# define Q_MAYBE_UNUSED [[maybe_unused]]
# define Q_CONSTEXPR2 constexpr
# define Q_CONSTEXPR2 constexpr // There's a Q_CONSTEXPR from Qt, which behaves differently.
#else
# define Q_NODISCARD
# define Q_MAYBE_UNUSED
@ -93,14 +92,6 @@ QT_END_NAMESPACE
using QT_ENTER_EVENT_TYPE = QEvent;
#endif
#ifndef Q_DECLARE_METATYPE2
# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
# define Q_DECLARE_METATYPE2 Q_DECLARE_METATYPE
# else
# define Q_DECLARE_METATYPE2(Type)
# endif
#endif
#ifndef QUtf8String
# define QUtf8String(str) QString::fromUtf8(str)
#endif
@ -215,7 +206,7 @@ Q_NAMESPACE_EXPORT(FRAMELESSHELPER_CORE_API)
// We have to use "qRound()" here because "std::round()" is not constexpr, yet.
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonSize = {qRound(qreal(kDefaultTitleBarHeight) * 1.5), kDefaultTitleBarHeight};
[[maybe_unused]] inline constexpr const QSize kDefaultSystemButtonIconSize = kDefaultWindowIconSize;
[[maybe_unused]] inline constexpr const QSize kDefaultWindowSize = {160, 160}; // Value taken from QPA.
[[maybe_unused]] inline constexpr const QSize kDefaultWindowSize = {160, 160}; // Value taken from Windows QPA.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
# define kDefaultBlackColor QColorConstants::Black
@ -466,105 +457,6 @@ struct VersionNumber
}
};
using InitializeHookCallback = std::function<void()>;
using UninitializeHookCallback = std::function<void()>;
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>;
using GetWindowSizeCallback = std::function<QSize()>;
using SetWindowSizeCallback = std::function<void(const QSize &)>;
using GetWindowPositionCallback = std::function<QPoint()>;
using SetWindowPositionCallback = std::function<void(const QPoint &)>;
using GetWindowScreenCallback = std::function<QScreen *()>;
using IsWindowFixedSizeCallback = std::function<bool()>;
using SetWindowFixedSizeCallback = std::function<void(const bool)>;
using GetWindowStateCallback = std::function<Qt::WindowState()>;
using SetWindowStateCallback = std::function<void(const Qt::WindowState)>;
using GetWindowHandleCallback = std::function<QWindow *()>;
using WindowToScreenCallback = std::function<QPoint(const QPoint &)>;
using ScreenToWindowCallback = std::function<QPoint(const QPoint &)>;
using IsInsideSystemButtonsCallback = std::function<bool(const QPoint &, SystemButtonType *)>;
using IsInsideTitleBarDraggableAreaCallback = std::function<bool(const QPoint &)>;
using GetWindowDevicePixelRatioCallback = std::function<qreal()>;
using SetSystemButtonStateCallback = std::function<void(const SystemButtonType, const ButtonState)>;
using GetWindowIdCallback = std::function<WId()>;
using ShouldIgnoreMouseEventsCallback = std::function<bool(const QPoint &)>;
using ShowSystemMenuCallback = std::function<void(const QPoint &)>;
using SetPropertyCallback = std::function<void(const QByteArray &, const QVariant &)>;
using GetPropertyCallback = std::function<QVariant(const QByteArray &, const QVariant &)>;
using SetCursorCallback = std::function<void(const QCursor &)>;
using UnsetCursorCallback = std::function<void()>;
using GetWidgetHandleCallback = std::function<QObject *()>;
struct SystemParameters
{
GetWindowFlagsCallback getWindowFlags = nullptr;
SetWindowFlagsCallback setWindowFlags = nullptr;
GetWindowSizeCallback getWindowSize = nullptr;
SetWindowSizeCallback setWindowSize = nullptr;
GetWindowPositionCallback getWindowPosition = nullptr;
SetWindowPositionCallback setWindowPosition = nullptr;
GetWindowScreenCallback getWindowScreen = nullptr;
IsWindowFixedSizeCallback isWindowFixedSize = nullptr;
SetWindowFixedSizeCallback setWindowFixedSize = nullptr;
GetWindowStateCallback getWindowState = nullptr;
SetWindowStateCallback setWindowState = nullptr;
GetWindowHandleCallback getWindowHandle = nullptr;
WindowToScreenCallback windowToScreen = nullptr;
ScreenToWindowCallback screenToWindow = nullptr;
IsInsideSystemButtonsCallback isInsideSystemButtons = nullptr;
IsInsideTitleBarDraggableAreaCallback isInsideTitleBarDraggableArea = nullptr;
GetWindowDevicePixelRatioCallback getWindowDevicePixelRatio = nullptr;
SetSystemButtonStateCallback setSystemButtonState = nullptr;
GetWindowIdCallback getWindowId = nullptr;
ShouldIgnoreMouseEventsCallback shouldIgnoreMouseEvents = nullptr;
ShowSystemMenuCallback showSystemMenu = nullptr;
SetPropertyCallback setProperty = nullptr;
GetPropertyCallback getProperty = nullptr;
SetCursorCallback setCursor = nullptr;
UnsetCursorCallback unsetCursor = nullptr;
GetWidgetHandleCallback getWidgetHandle = nullptr;
[[nodiscard]] inline bool isValid() const
{
Q_ASSERT(getWindowFlags);
Q_ASSERT(setWindowFlags);
Q_ASSERT(getWindowSize);
Q_ASSERT(setWindowSize);
Q_ASSERT(getWindowPosition);
Q_ASSERT(setWindowPosition);
Q_ASSERT(getWindowScreen);
Q_ASSERT(isWindowFixedSize);
Q_ASSERT(setWindowFixedSize);
Q_ASSERT(getWindowState);
Q_ASSERT(setWindowState);
Q_ASSERT(getWindowHandle);
Q_ASSERT(windowToScreen);
Q_ASSERT(screenToWindow);
Q_ASSERT(isInsideSystemButtons);
Q_ASSERT(isInsideTitleBarDraggableArea);
Q_ASSERT(getWindowDevicePixelRatio);
Q_ASSERT(setSystemButtonState);
Q_ASSERT(getWindowId);
Q_ASSERT(shouldIgnoreMouseEvents);
Q_ASSERT(showSystemMenu);
Q_ASSERT(setProperty);
Q_ASSERT(getProperty);
Q_ASSERT(setCursor);
Q_ASSERT(unsetCursor);
Q_ASSERT(getWidgetHandle);
return (getWindowFlags && setWindowFlags && getWindowSize
&& setWindowSize && getWindowPosition && setWindowPosition
&& getWindowScreen && isWindowFixedSize && setWindowFixedSize
&& getWindowState && setWindowState && getWindowHandle
&& windowToScreen && screenToWindow && isInsideSystemButtons
&& isInsideTitleBarDraggableArea && getWindowDevicePixelRatio
&& setSystemButtonState && getWindowId && shouldIgnoreMouseEvents
&& showSystemMenu && setProperty && getProperty && setCursor
&& unsetCursor && getWidgetHandle);
}
};
struct VersionInfo
{
int version = 0;
@ -622,19 +514,12 @@ namespace FramelessHelper::Core
FRAMELESSHELPER_CORE_API void initialize();
FRAMELESSHELPER_CORE_API void uninitialize();
[[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo version();
FRAMELESSHELPER_CORE_API void registerInitializeHook(const Global::InitializeHookCallback &cb);
FRAMELESSHELPER_CORE_API void registerUninitializeHook(const Global::UninitializeHookCallback &cb);
FRAMELESSHELPER_CORE_API void setApplicationOSThemeAware();
FRAMELESSHELPER_CORE_API void outputLogo();
} // namespace FramelessHelper::Core
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber)
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::SystemParameters)
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionInfo)
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::Dpi);
#ifndef QT_NO_DEBUG_STREAM
QT_BEGIN_NAMESPACE
FRAMELESSHELPER_CORE_API QDebug operator<<(QDebug, const FRAMELESSHELPER_PREPEND_NAMESPACE(Global)::VersionNumber &);

View File

@ -28,6 +28,7 @@
FRAMELESSHELPER_BEGIN_NAMESPACE
struct SystemParameters;
class FramelessManagerPrivate;
class FRAMELESSHELPER_CORE_API FramelessManager : public QObject
@ -52,7 +53,7 @@ public:
Q_NODISCARD Global::WallpaperAspectStyle wallpaperAspectStyle() const;
public Q_SLOTS:
void addWindow(const Global::SystemParameters &params);
void addWindow(const SystemParameters *params);
void removeWindow(const WId windowId);
Q_SIGNALS:
@ -64,5 +65,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManager))

View File

@ -67,5 +67,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(MicaMaterial))

View File

@ -73,5 +73,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(ChromePalettePrivate))

View File

@ -49,5 +49,3 @@ public:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessConfig))

View File

@ -0,0 +1,103 @@
/*
* MIT License
*
* Copyright (C) 2021-2023 by wangwenx190 (Yuhang Zhao)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#pragma once
#include <FramelessHelper/Core/framelesshelpercore_global.h>
QT_BEGIN_NAMESPACE
class QScreen;
QT_END_NAMESPACE
FRAMELESSHELPER_BEGIN_NAMESPACE
using InitializeHookCallback = std::function<void()>;
using UninitializeHookCallback = std::function<void()>;
using GetWindowFlagsCallback = std::function<Qt::WindowFlags()>;
using SetWindowFlagsCallback = std::function<void(const Qt::WindowFlags)>;
using GetWindowSizeCallback = std::function<QSize()>;
using SetWindowSizeCallback = std::function<void(const QSize &)>;
using GetWindowPositionCallback = std::function<QPoint()>;
using SetWindowPositionCallback = std::function<void(const QPoint &)>;
using GetWindowScreenCallback = std::function<QScreen *()>;
using IsWindowFixedSizeCallback = std::function<bool()>;
using SetWindowFixedSizeCallback = std::function<void(const bool)>;
using GetWindowStateCallback = std::function<Qt::WindowState()>;
using SetWindowStateCallback = std::function<void(const Qt::WindowState)>;
using GetWindowHandleCallback = std::function<QWindow *()>;
using WindowToScreenCallback = std::function<QPoint(const QPoint &)>;
using ScreenToWindowCallback = std::function<QPoint(const QPoint &)>;
using IsInsideSystemButtonsCallback = std::function<bool(const QPoint &, Global::SystemButtonType *)>;
using IsInsideTitleBarDraggableAreaCallback = std::function<bool(const QPoint &)>;
using GetWindowDevicePixelRatioCallback = std::function<qreal()>;
using SetSystemButtonStateCallback = std::function<void(const Global::SystemButtonType, const Global::ButtonState)>;
using GetWindowIdCallback = std::function<WId()>;
using ShouldIgnoreMouseEventsCallback = std::function<bool(const QPoint &)>;
using ShowSystemMenuCallback = std::function<void(const QPoint &)>;
using SetPropertyCallback = std::function<void(const QByteArray &, const QVariant &)>;
using GetPropertyCallback = std::function<QVariant(const QByteArray &, const QVariant &)>;
using SetCursorCallback = std::function<void(const QCursor &)>;
using UnsetCursorCallback = std::function<void()>;
using GetWidgetHandleCallback = std::function<QObject *()>;
struct SystemParameters
{
GetWindowFlagsCallback getWindowFlags = nullptr;
SetWindowFlagsCallback setWindowFlags = nullptr;
GetWindowSizeCallback getWindowSize = nullptr;
SetWindowSizeCallback setWindowSize = nullptr;
GetWindowPositionCallback getWindowPosition = nullptr;
SetWindowPositionCallback setWindowPosition = nullptr;
GetWindowScreenCallback getWindowScreen = nullptr;
IsWindowFixedSizeCallback isWindowFixedSize = nullptr;
SetWindowFixedSizeCallback setWindowFixedSize = nullptr;
GetWindowStateCallback getWindowState = nullptr;
SetWindowStateCallback setWindowState = nullptr;
GetWindowHandleCallback getWindowHandle = nullptr;
WindowToScreenCallback windowToScreen = nullptr;
ScreenToWindowCallback screenToWindow = nullptr;
IsInsideSystemButtonsCallback isInsideSystemButtons = nullptr;
IsInsideTitleBarDraggableAreaCallback isInsideTitleBarDraggableArea = nullptr;
GetWindowDevicePixelRatioCallback getWindowDevicePixelRatio = nullptr;
SetSystemButtonStateCallback setSystemButtonState = nullptr;
GetWindowIdCallback getWindowId = nullptr;
ShouldIgnoreMouseEventsCallback shouldIgnoreMouseEvents = nullptr;
ShowSystemMenuCallback showSystemMenu = nullptr;
SetPropertyCallback setProperty = nullptr;
GetPropertyCallback getProperty = nullptr;
SetCursorCallback setCursor = nullptr;
UnsetCursorCallback unsetCursor = nullptr;
GetWidgetHandleCallback getWidgetHandle = nullptr;
};
using FramelessParams = SystemParameters *;
using FramelessParamsConst = const SystemParameters *;
using FramelessParamsRef = SystemParameters &;
using FramelessParamsConstRef = const SystemParameters &;
FRAMELESSHELPER_CORE_API void registerInitializeHook(const InitializeHookCallback &cb);
FRAMELESSHELPER_CORE_API void registerUninitializeHook(const UninitializeHookCallback &cb);
FRAMELESSHELPER_END_NAMESPACE

View File

@ -24,7 +24,7 @@
#pragma once
#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <FramelessHelper/Core/private/framelesshelpercore_global_p.h>
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -51,7 +51,7 @@ public:
Q_NODISCARD QString wallpaper() const;
Q_NODISCARD Global::WallpaperAspectStyle wallpaperAspectStyle() const;
static void addWindow(const Global::SystemParameters &params);
static void addWindow(FramelessParamsConst params);
static void removeWindow(const WId windowId);
Q_INVOKABLE void notifySystemThemeHasChangedOrNot();
@ -74,5 +74,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessManagerPrivate))

View File

@ -63,5 +63,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(MicaMaterialPrivate))

View File

@ -90,5 +90,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(RegistryKey))

View File

@ -56,8 +56,6 @@ public:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader))
#define API_AVAILABLE(lib, func) \
(FRAMELESSHELPER_PREPEND_NAMESPACE(SysApiLoader)::instance()->isAvailable(k##lib, k##func))

View File

@ -62,5 +62,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(WindowBorderPainterPrivate))

View File

@ -31,6 +31,8 @@
FRAMELESSHELPER_BEGIN_NAMESPACE
struct SystemParameters;
namespace Utils
{
@ -43,10 +45,7 @@ FRAMELESSHELPER_CORE_API void startSystemResize(QWindow *window, const Qt::Edges
[[nodiscard]] FRAMELESSHELPER_CORE_API QString getSystemButtonGlyph(const Global::SystemButtonType button);
[[nodiscard]] FRAMELESSHELPER_CORE_API QWindow *findWindow(const WId windowId);
FRAMELESSHELPER_CORE_API void moveWindowToDesktopCenter(
const Global::GetWindowScreenCallback &getWindowScreen,
const Global::GetWindowSizeCallback &getWindowSize,
const Global::SetWindowPositionCallback &setWindowPosition,
const bool considerTaskBar);
const SystemParameters *params, const bool considerTaskBar);
[[nodiscard]] FRAMELESSHELPER_CORE_API Global::SystemTheme getSystemTheme();
[[nodiscard]] FRAMELESSHELPER_CORE_API Qt::WindowState windowStatesToWindowState(
const Qt::WindowStates states);
@ -84,10 +83,8 @@ FRAMELESSHELPER_CORE_API void updateInternalWindowFrameMargins(QWindow *window,
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowNoState(const WId windowId);
FRAMELESSHELPER_CORE_API void syncWmPaintWithDwm();
FRAMELESSHELPER_CORE_API void showSystemMenu(
const WId windowId,
const QPoint &pos,
const bool selectFirstEntry,
const Global::IsWindowFixedSizeCallback &isWindowFixedSize);
const WId windowId, const QPoint &pos,
const bool selectFirstEntry, const SystemParameters *params);
[[nodiscard]] FRAMELESSHELPER_CORE_API QColor getDwmColorizationColor();
[[nodiscard]] FRAMELESSHELPER_CORE_API Global::DwmColorizationArea getDwmColorizationArea();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isHighContrastModeEnabled();
@ -109,10 +106,7 @@ FRAMELESSHELPER_CORE_API void maybeFixupQtInternals(const WId windowId);
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isWindowFrameBorderVisible();
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isFrameBorderColorized();
FRAMELESSHELPER_CORE_API void installSystemMenuHook(
const WId windowId,
const Global::IsWindowFixedSizeCallback &isWindowFixedSize,
const Global::IsInsideTitleBarDraggableAreaCallback &isInTitleBarArea,
const Global::GetWindowHandleCallback &getWindowHandle);
const WId windowId, const SystemParameters *params);
FRAMELESSHELPER_CORE_API void uninstallSystemMenuHook(const WId windowId);
FRAMELESSHELPER_CORE_API void setAeroSnappingEnabled(const WId windowId, const bool enable);
FRAMELESSHELPER_CORE_API void tryToEnableHighestDpiAwarenessLevel();

View File

@ -80,5 +80,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(WindowBorderPainter))

View File

@ -151,5 +151,3 @@ FRAMELESSHELPER_QUICK_API void uninitialize();
} // namespace FramelessHelper::Quick
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickGlobal))

View File

@ -104,6 +104,4 @@ private:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper))
QML_DECLARE_TYPEINFO(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelper), QML_HAS_ATTACHED_PROPERTIES)

View File

@ -88,6 +88,3 @@ Q_SIGNALS:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickUtils))

View File

@ -82,7 +82,4 @@ private:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickApplicationWindow))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickApplicationWindow))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -70,6 +70,4 @@ private:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickApplicationWindowPrivate))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -104,5 +104,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickHelperPrivate))

View File

@ -82,7 +82,4 @@ private:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindow))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -70,6 +70,4 @@ private:
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessQuickWindowPrivate))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -64,5 +64,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickImageItemPrivate))

View File

@ -60,5 +60,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickMicaMaterialPrivate))

View File

@ -108,9 +108,6 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardSystemButton))
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -146,9 +146,6 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickStandardTitleBar))
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#endif // FRAMELESSHELPER_QUICK_NO_PRIVATE

View File

@ -61,5 +61,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickWindowBorderPrivate))

View File

@ -49,6 +49,3 @@ protected:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickChromePalette))

View File

@ -63,6 +63,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickImageItem))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickImageItem))

View File

@ -55,6 +55,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickMicaMaterial))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickMicaMaterial))

View File

@ -89,6 +89,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickWindowBorder))
QML_DECLARE_TYPE(FRAMELESSHELPER_PREPEND_NAMESPACE(QuickWindowBorder))

View File

@ -46,5 +46,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessDialog))

View File

@ -61,5 +61,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindow))

View File

@ -61,5 +61,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidget))

View File

@ -90,5 +90,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelper))

View File

@ -55,5 +55,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessDialogPrivate))

View File

@ -62,5 +62,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessMainWindowPrivate))

View File

@ -62,5 +62,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetPrivate))

View File

@ -105,5 +105,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(FramelessWidgetsHelperPrivate))

View File

@ -99,5 +99,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButtonPrivate))

View File

@ -124,5 +124,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBarPrivate))

View File

@ -89,5 +89,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(WidgetsSharedHelper))

View File

@ -102,5 +102,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardSystemButton))

View File

@ -104,5 +104,3 @@ private:
};
FRAMELESSHELPER_END_NAMESPACE
Q_DECLARE_METATYPE2(FRAMELESSHELPER_PREPEND_NAMESPACE(StandardTitleBar))

View File

@ -38,7 +38,8 @@ HEADERS += \
$$CORE_PRIV_INC_DIR/framelessmanager_p.h \
$$CORE_PRIV_INC_DIR/micamaterial_p.h \
$$CORE_PRIV_INC_DIR/sysapiloader_p.h \
$$CORE_PRIV_INC_DIR/windowborderpainter_p.h
$$CORE_PRIV_INC_DIR/windowborderpainter_p.h \
$$CORE_PRIV_INC_DIR/framelesshelpercore_global_p.h
SOURCES += \
$$CORE_SRC_DIR/chromepalette.cpp \

View File

@ -83,6 +83,7 @@ set(PRIVATE_HEADERS
${INCLUDE_PREFIX}/private/chromepalette_p.h
${INCLUDE_PREFIX}/private/micamaterial_p.h
${INCLUDE_PREFIX}/private/windowborderpainter_p.h
${INCLUDE_PREFIX}/private/framelesshelpercore_global_p.h
)
set(SOURCES

View File

@ -26,6 +26,7 @@
#include "framelessmanager.h"
#include "framelessmanager_p.h"
#include "framelessconfig_p.h"
#include "framelesshelpercore_global_p.h"
#include "utils.h"
#include <QtCore/qmutex.h>
#include <QtCore/qloggingcategory.h>
@ -70,21 +71,21 @@ FramelessHelperQt::FramelessHelperQt(QObject *parent) : QObject(parent) {}
FramelessHelperQt::~FramelessHelperQt() = default;
void FramelessHelperQt::addWindow(const SystemParameters &params)
void FramelessHelperQt::addWindow(FramelessParamsConst params)
{
Q_ASSERT(params.isValid());
if (!params.isValid()) {
Q_ASSERT(params);
if (!params) {
return;
}
const WId windowId = params.getWindowId();
const WId windowId = params->getWindowId();
g_qtHelper()->mutex.lock();
if (g_qtHelper()->data.contains(windowId)) {
g_qtHelper()->mutex.unlock();
return;
}
QtHelperData data = {};
data.params = params;
QWindow *window = params.getWindowHandle();
data.params = *params;
QWindow *window = params->getWindowHandle();
// Give it a parent so that it can be deleted even if we forget to do so.
data.eventFilter = new FramelessHelperQt(window);
g_qtHelper()->data.insert(windowId, data);
@ -102,7 +103,7 @@ void FramelessHelperQt::addWindow(const SystemParameters &params)
window->setProperty("_q_mac_wantsLayer", 1);
#endif // (defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
if (shouldApplyFramelessFlag) {
params.setWindowFlags(params.getWindowFlags() | Qt::FramelessWindowHint);
params->setWindowFlags(params->getWindowFlags() | Qt::FramelessWindowHint);
} else {
#ifdef Q_OS_LINUX
Q_UNUSED(Utils::tryHideSystemTitleBar(windowId, true));

View File

@ -29,6 +29,7 @@
#include "utils.h"
#include "winverhelper_p.h"
#include "framelesshelper_windows.h"
#include "framelesshelpercore_global_p.h"
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include <QtCore/qvariant.h>
@ -452,7 +453,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper)
wcex.lpfnWndProc = FallbackTitleBarWindowProc;
wcex.hInstance = instance;
if (RegisterClassExW(&wcex) != INVALID_ATOM) {
FramelessHelper::Core::registerUninitializeHook([](){
registerUninitializeHook([](){
const HINSTANCE instance = GetModuleHandleW(nullptr);
if (!instance) {
//WARNING << Utils::getSystemErrorMessage(kGetModuleHandleW);
@ -508,20 +509,20 @@ FramelessHelperWin::FramelessHelperWin() : QAbstractNativeEventFilter() {}
FramelessHelperWin::~FramelessHelperWin() = default;
void FramelessHelperWin::addWindow(const SystemParameters &params)
void FramelessHelperWin::addWindow(FramelessParamsConst params)
{
Q_ASSERT(params.isValid());
if (!params.isValid()) {
Q_ASSERT(params);
if (!params) {
return;
}
const WId windowId = params.getWindowId();
const WId windowId = params->getWindowId();
g_win32Helper()->mutex.lock();
if (g_win32Helper()->data.contains(windowId)) {
g_win32Helper()->mutex.unlock();
return;
}
Win32HelperData data = {};
data.params = params;
data.params = *params;
data.dpi = {Utils::getWindowDpi(windowId, true), Utils::getWindowDpi(windowId, false)};
g_win32Helper()->data.insert(windowId, data);
if (!g_win32Helper()->nativeEventFilter) {
@ -531,7 +532,7 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
g_win32Helper()->mutex.unlock();
DEBUG.noquote() << "The DPI of window" << hwnd2str(windowId) << "is" << data.dpi;
#if 0
params.setWindowFlags(params.getWindowFlags() | Qt::FramelessWindowHint);
params->setWindowFlags(params->getWindowFlags() | Qt::FramelessWindowHint);
// We need some delay here, otherwise the window styles will be overwritten by
// QPA itself. But don't use QThread::sleep(), it doesn't help in our case.
QTimer::singleShot(0, qApp, [windowId](){
@ -542,7 +543,7 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
// otherwise we'll get lots of warning messages when we change the window
// geometry, it will also affect the final window geometry because QPA will
// always take it into account when setting window size and position.
Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true);
Utils::updateInternalWindowFrameMargins(params->getWindowHandle(), true);
#endif
// Tell DWM our preferred frame margin.
Utils::updateWindowFrameMargins(windowId, false);
@ -557,8 +558,8 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
FramelessHelper::Core::setApplicationOSThemeAware();
if (WindowsVersionHelper::isWin10RS5OrGreater()) {
const bool dark = Utils::shouldAppsUseDarkMode();
const auto isWidget = [&params]() -> bool {
const auto widget = params.getWidgetHandle();
const auto isWidget = [params]() -> bool {
const auto widget = params->getWidgetHandle();
return (widget && widget->isWidgetType());
}();
if (!isWidget) {
@ -571,7 +572,7 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
// The fallback title bar window is only used to activate the Snap Layout feature
// introduced in Windows 11, so it's not necessary to create it on systems below Win11.
if (!FramelessConfig::instance()->isSet(Option::DisableWindowsSnapLayout)) {
if (!createFallbackTitleBarWindow(windowId, params.isWindowFixedSize())) {
if (!createFallbackTitleBarWindow(windowId, params->isWindowFixedSize())) {
WARNING << "Failed to create the fallback title bar window.";
}
}

View File

@ -23,25 +23,8 @@
*/
#include "framelesshelpercore_global.h"
#include "framelesshelpercore_global_p.h"
#include "utils.h"
#include "framelessmanager.h"
#include "framelesshelper_qt.h"
#include "chromepalette.h"
#include "micamaterial.h"
#include "windowborderpainter.h"
#include "sysapiloader_p.h"
#include "framelessmanager_p.h"
#include "framelessconfig_p.h"
#include "chromepalette_p.h"
#include "micamaterial_p.h"
#include "windowborderpainter_p.h"
#ifdef Q_OS_WINDOWS
# include "framelesshelper_win.h"
# include "registrykey_p.h"
#endif
#ifdef Q_OS_LINUX
# include "framelesshelper_linux.h"
#endif
#include <QtCore/qmutex.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qcoreapplication.h>
@ -155,6 +138,26 @@ struct CoreData
Q_GLOBAL_STATIC(CoreData, coreData)
void registerInitializeHook(const InitializeHookCallback &cb)
{
Q_ASSERT(cb);
if (!cb) {
return;
}
const QMutexLocker locker(&coreData()->mutex);
coreData()->initHooks.append(cb);
}
void registerUninitializeHook(const UninitializeHookCallback &cb)
{
Q_ASSERT(cb);
if (!cb) {
return;
}
const QMutexLocker locker(&coreData()->mutex);
coreData()->uninitHooks.append(cb);
}
namespace FramelessHelper::Core
{
@ -175,8 +178,8 @@ void initialize()
// enough, that is, before the construction of any Q(Gui)Application
// instances. QCoreApplication won't instantiate the platform plugin.
qputenv(QT_QPA_ENV_VAR, kxcb);
XInitThreads();
gtk_init(nullptr, nullptr);
XInitThreads(); // Users report that GTK is crashing without this.
gtk_init(nullptr, nullptr); // Users report that GTK functionalities won't work without this.
#endif
#if (defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)))
@ -211,51 +214,6 @@ void initialize()
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
qRegisterMetaType<Option>();
qRegisterMetaType<SystemTheme>();
qRegisterMetaType<SystemButtonType>();
#ifdef Q_OS_WINDOWS
qRegisterMetaType<DwmColorizationArea>();
#endif
qRegisterMetaType<ButtonState>();
#ifdef Q_OS_WINDOWS
qRegisterMetaType<WindowsVersion>();
#endif
qRegisterMetaType<BlurMode>();
qRegisterMetaType<WallpaperAspectStyle>();
# ifdef Q_OS_WINDOWS
qRegisterMetaType<RegistryRootKey>();
# endif
qRegisterMetaType<WindowEdge>();
qRegisterMetaType<WindowEdges>();
# ifdef Q_OS_WINDOWS
qRegisterMetaType<DpiAwareness>();
# endif
qRegisterMetaType<WindowCornerStyle>();
qRegisterMetaType<VersionNumber>();
qRegisterMetaType<SystemParameters>();
qRegisterMetaType<VersionInfo>();
qRegisterMetaType<Dpi>();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
qRegisterMetaType<FramelessManager>();
# ifdef Q_OS_WINDOWS
qRegisterMetaType<FramelessHelperWin>();
# endif
qRegisterMetaType<FramelessHelperQt>();
qRegisterMetaType<ChromePalette>();
qRegisterMetaType<SysApiLoader>();
qRegisterMetaType<FramelessManagerPrivate>();
qRegisterMetaType<FramelessConfig>();
qRegisterMetaType<ChromePalettePrivate>();
qRegisterMetaType<MicaMaterial>();
qRegisterMetaType<MicaMaterialPrivate>();
qRegisterMetaType<WindowBorderPainter>();
qRegisterMetaType<WindowBorderPainterPrivate>();
# ifdef Q_OS_WINDOWS
qRegisterMetaType<RegistryKey>();
# endif
#endif
const QMutexLocker locker(&coreData()->mutex);
if (!coreData()->initHooks.isEmpty()) {
for (auto &&hook : std::as_const(coreData()->initHooks)) {
@ -320,26 +278,6 @@ VersionInfo version()
return result;
}
void registerInitializeHook(const InitializeHookCallback &cb)
{
Q_ASSERT(cb);
if (!cb) {
return;
}
const QMutexLocker locker(&coreData()->mutex);
coreData()->initHooks.append(cb);
}
void registerUninitializeHook(const UninitializeHookCallback &cb)
{
Q_ASSERT(cb);
if (!cb) {
return;
}
const QMutexLocker locker(&coreData()->mutex);
coreData()->uninitHooks.append(cb);
}
void setApplicationOSThemeAware()
{
static bool set = false;

View File

@ -0,0 +1 @@
#include "../../include/FramelessHelper/Core/private/framelesshelpercore_global_p.h"

View File

@ -26,6 +26,7 @@
#include "framelessmanager_p.h"
#include "framelesshelper_qt.h"
#include "framelessconfig_p.h"
#include "framelesshelpercore_global_p.h"
#include "utils.h"
#ifdef Q_OS_WINDOWS
# include "framelesshelper_win.h"
@ -200,13 +201,13 @@ WallpaperAspectStyle FramelessManagerPrivate::wallpaperAspectStyle() const
return m_wallpaperAspectStyle;
}
void FramelessManagerPrivate::addWindow(const SystemParameters &params)
void FramelessManagerPrivate::addWindow(FramelessParamsConst params)
{
Q_ASSERT(params.isValid());
if (!params.isValid()) {
Q_ASSERT(params);
if (!params) {
return;
}
const WId windowId = params.getWindowId();
const WId windowId = params->getWindowId();
g_helper()->mutex.lock();
if (g_helper()->windowIds.contains(windowId)) {
g_helper()->mutex.unlock();
@ -222,8 +223,7 @@ void FramelessManagerPrivate::addWindow(const SystemParameters &params)
if (!pureQt) {
FramelessHelperWin::addWindow(params);
}
Utils::installSystemMenuHook(windowId, params.isWindowFixedSize,
params.isInsideTitleBarDraggableArea, params.getWindowHandle);
Utils::installSystemMenuHook(windowId, params);
#endif
}
@ -408,7 +408,7 @@ WallpaperAspectStyle FramelessManager::wallpaperAspectStyle() const
return d->wallpaperAspectStyle();
}
void FramelessManager::addWindow(const SystemParameters &params)
void FramelessManager::addWindow(FramelessParamsConst params)
{
Q_D(FramelessManager);
d->addWindow(params);

View File

@ -23,6 +23,7 @@
*/
#include "utils.h"
#include "framelesshelpercore_global_p.h"
#ifdef Q_OS_WINDOWS
# include "winverhelper_p.h"
#endif // Q_OS_WINDOWS
@ -191,22 +192,17 @@ QWindow *Utils::findWindow(const WId windowId)
return nullptr;
}
void Utils::moveWindowToDesktopCenter(const GetWindowScreenCallback &getWindowScreen,
const GetWindowSizeCallback &getWindowSize,
const SetWindowPositionCallback &setWindowPosition,
const bool considerTaskBar)
void Utils::moveWindowToDesktopCenter(FramelessParamsConst params, const bool considerTaskBar)
{
Q_ASSERT(getWindowScreen);
Q_ASSERT(getWindowSize);
Q_ASSERT(setWindowPosition);
if (!getWindowScreen || !getWindowSize || !setWindowPosition) {
Q_ASSERT(params);
if (!params) {
return;
}
const QSize windowSize = getWindowSize();
const QSize windowSize = params->getWindowSize();
if (windowSize.isEmpty() || (windowSize == kDefaultWindowSize)) {
return;
}
const QScreen *screen = getWindowScreen();
const QScreen *screen = params->getWindowScreen();
if (!screen) {
screen = QGuiApplication::primaryScreen();
}
@ -218,7 +214,7 @@ void Utils::moveWindowToDesktopCenter(const GetWindowScreenCallback &getWindowSc
const QPoint offset = (considerTaskBar ? screen->availableVirtualGeometry().topLeft() : QPoint(0, 0));
const int newX = std::round(qreal(screenSize.width() - windowSize.width()) / 2.0);
const int newY = std::round(qreal(screenSize.height() - windowSize.height()) / 2.0);
setWindowPosition(QPoint(newX + offset.x(), newY + offset.y()));
params->setWindowPosition(QPoint(newX + offset.x(), newY + offset.y()));
}
Qt::WindowState Utils::windowStatesToWindowState(const Qt::WindowStates states)

View File

@ -29,6 +29,7 @@
#include "sysapiloader_p.h"
#include "registrykey_p.h"
#include "winverhelper_p.h"
#include "framelesshelpercore_global_p.h"
#include <QtCore/qmutex.h>
#include <QtCore/qhash.h>
#include <QtCore/qloggingcategory.h>
@ -48,7 +49,9 @@
#endif // FRAMELESSHELPER_CORE_NO_PRIVATE
#include <d2d1.h>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Q_DECLARE_METATYPE(QMargins)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -185,9 +188,7 @@ FRAMELESSHELPER_STRING_CONSTANT(SetActiveWindow)
struct Win32UtilsHelperData
{
WNDPROC originalWindowProc = nullptr;
IsWindowFixedSizeCallback isWindowFixedSize = nullptr;
IsInsideTitleBarDraggableAreaCallback isInTitleBarArea = nullptr;
GetWindowHandleCallback getWindowHandle = nullptr;
SystemParameters params = {};
};
struct Win32UtilsHelper
@ -510,8 +511,8 @@ static inline void moveWindowToMonitor(const HWND hwnd, const MONITORINFOEXW &ac
switch (uMsg) {
case WM_RBUTTONUP: {
const QPoint nativeLocalPos = getNativePosFromMouse();
const QPoint qtScenePos = Utils::fromNativePixels(data.getWindowHandle(), nativeLocalPos);
if (data.isInTitleBarArea(qtScenePos)) {
const QPoint qtScenePos = Utils::fromNativePixels(data.params.getWindowHandle(), nativeLocalPos);
if (data.params.isInsideTitleBarDraggableArea(qtScenePos)) {
POINT pos = {nativeLocalPos.x(), nativeLocalPos.y()};
if (ClientToScreen(hWnd, &pos) == FALSE) {
WARNING << Utils::getSystemErrorMessage(kClientToScreen);
@ -549,7 +550,7 @@ static inline void moveWindowToMonitor(const HWND hwnd, const MONITORINFOEXW &ac
break;
}
if (shouldShowSystemMenu) {
Utils::showSystemMenu(windowId, nativeGlobalPos, broughtByKeyboard, data.isWindowFixedSize);
Utils::showSystemMenu(windowId, nativeGlobalPos, broughtByKeyboard, &data.params);
// QPA's internal code will handle system menu events separately, and its
// behavior is not what we would want to see because it doesn't know our
// window doesn't have any window frame now, so return early here to avoid
@ -761,11 +762,11 @@ DwmColorizationArea Utils::getDwmColorizationArea()
}
void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool selectFirstEntry,
const IsWindowFixedSizeCallback &isWindowFixedSize)
FramelessParamsConst params)
{
Q_ASSERT(windowId);
Q_ASSERT(isWindowFixedSize);
if (!windowId || !isWindowFixedSize) {
Q_ASSERT(params);
if (!windowId || !params) {
return;
}
@ -780,7 +781,7 @@ void Utils::showSystemMenu(const WId windowId, const QPoint &pos, const bool sel
// Tweak the menu items according to the current window status.
const bool maxOrFull = (IsMaximized(hWnd) || isFullScreen(windowId));
const bool fixedSize = isWindowFixedSize();
const bool fixedSize = params->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
// up by keyboard. I don't know how to pre-select a menu item but it seems
@ -1381,14 +1382,11 @@ bool Utils::isFrameBorderColorized()
return isTitleBarColorized();
}
void Utils::installSystemMenuHook(const WId windowId,
const IsWindowFixedSizeCallback &isWindowFixedSize,
const IsInsideTitleBarDraggableAreaCallback &isInTitleBarArea,
const GetWindowHandleCallback &getWindowHandle)
void Utils::installSystemMenuHook(const WId windowId, FramelessParamsConst params)
{
Q_ASSERT(windowId);
Q_ASSERT(isWindowFixedSize);
if (!windowId || !isWindowFixedSize) {
Q_ASSERT(params);
if (!windowId || !params) {
return;
}
const QMutexLocker locker(&g_utilsHelper()->mutex);
@ -1411,9 +1409,7 @@ void Utils::installSystemMenuHook(const WId windowId,
//triggerFrameChange(windowId); // Crash
Win32UtilsHelperData data = {};
data.originalWindowProc = originalWindowProc;
data.isWindowFixedSize = isWindowFixedSize;
data.isInTitleBarArea = isInTitleBarArea;
data.getWindowHandle = getWindowHandle;
data.params = *params;
g_utilsHelper()->data.insert(windowId, data);
}

View File

@ -23,26 +23,6 @@
*/
#include "framelesshelperquick_global.h"
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
# include "framelessquickhelper.h"
# include "framelessquickhelper_p.h"
# include "framelessquickutils.h"
# include "quickchromepalette.h"
# include "quickmicamaterial.h"
# include "quickmicamaterial_p.h"
# include "quickimageitem.h"
# include "quickimageitem_p.h"
# include "quickwindowborder.h"
# include "quickwindowborder_p.h"
# ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE
# include "quickstandardsystembutton_p.h"
# include "quickstandardtitlebar_p.h"
# include "framelessquickwindow_p.h"
# include "framelessquickwindow_p_p.h"
# include "framelessquickapplicationwindow_p.h"
# include "framelessquickapplicationwindow_p_p.h"
# endif // FRAMELESSHELPER_QUICK_NO_PRIVATE
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#include <QtCore/qloggingcategory.h>
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -79,45 +59,6 @@ void initialize()
inited = true;
FramelessHelper::Core::initialize();
qRegisterMetaType<QuickGlobal::SystemTheme>();
qRegisterMetaType<QuickGlobal::SystemButtonType>();
qRegisterMetaType<QuickGlobal::ButtonState>();
qRegisterMetaType<QuickGlobal::BlurMode>();
qRegisterMetaType<QuickGlobal::WindowEdge>();
qRegisterMetaType<QuickGlobal::WindowEdges>();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
qRegisterMetaType<QuickGlobal>();
qRegisterMetaType<FramelessQuickHelper>();
qRegisterMetaType<FramelessQuickHelper *>();
qRegisterMetaType<FramelessQuickHelperPrivate>();
qRegisterMetaType<FramelessQuickUtils>();
qRegisterMetaType<FramelessQuickUtils *>();
qRegisterMetaType<QuickChromePalette>();
qRegisterMetaType<QuickChromePalette *>();
qRegisterMetaType<QuickMicaMaterial>();
qRegisterMetaType<QuickMicaMaterial *>();
qRegisterMetaType<QuickMicaMaterialPrivate>();
qRegisterMetaType<QuickImageItem>();
qRegisterMetaType<QuickImageItem *>();
qRegisterMetaType<QuickImageItemPrivate>();
qRegisterMetaType<QuickWindowBorder>();
qRegisterMetaType<QuickWindowBorder *>();
qRegisterMetaType<QuickWindowBorderPrivate>();
# ifndef FRAMELESSHELPER_QUICK_NO_PRIVATE
qRegisterMetaType<QuickStandardSystemButton>();
qRegisterMetaType<QuickStandardSystemButton *>();
qRegisterMetaType<QuickStandardTitleBar>();
qRegisterMetaType<QuickStandardTitleBar *>();
qRegisterMetaType<FramelessQuickWindow>();
qRegisterMetaType<FramelessQuickWindow *>();
qRegisterMetaType<FramelessQuickWindowPrivate>();
qRegisterMetaType<FramelessQuickApplicationWindow>();
qRegisterMetaType<FramelessQuickApplicationWindow *>();
qRegisterMetaType<FramelessQuickApplicationWindowPrivate>();
# endif // FRAMELESSHELPER_QUICK_NO_PRIVATE
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
}
void uninitialize()

View File

@ -27,8 +27,9 @@
#include "quickmicamaterial.h"
#include "quickwindowborder.h"
#include <FramelessHelper/Core/framelessmanager.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/private/framelesshelpercore_global_p.h>
#ifdef Q_OS_WINDOWS
# include <FramelessHelper/Core/private/winverhelper_p.h>
#endif // Q_OS_WINDOWS
@ -223,7 +224,7 @@ void FramelessQuickHelperPrivate::attach()
params.unsetCursor = [window]() -> void { window->unsetCursor(); };
params.getWidgetHandle = []() -> QObject * { return nullptr; };
FramelessManager::instance()->addWindow(params);
FramelessManager::instance()->addWindow(&params);
g_quickHelper()->mutex.lock();
data->params = params;
@ -361,7 +362,8 @@ void FramelessQuickHelperPrivate::showSystemMenu(const QPoint &pos)
const QPoint globalPos = window->mapToGlobal(pos);
const QPoint nativePos = Utils::toNativePixels(window, globalPos);
#ifdef Q_OS_WINDOWS
Utils::showSystemMenu(windowId, nativePos, false, [this]() -> bool { return isWindowFixedSize(); });
const SystemParameters params = getWindowData().params;
Utils::showSystemMenu(windowId, nativePos, false, &params);
#elif defined(Q_OS_LINUX)
Utils::openSystemMenu(windowId, nativePos);
#else
@ -400,9 +402,8 @@ void FramelessQuickHelperPrivate::moveWindowToDesktopCenter()
if (!window) {
return;
}
Utils::moveWindowToDesktopCenter([window]() -> QScreen * { return window->screen(); },
[window]() -> QSize { return window->size(); },
[window](const QPoint &pos) -> void { window->setX(pos.x()); window->setY(pos.y()); }, true);
const SystemParameters params = getWindowData().params;
Utils::moveWindowToDesktopCenter(&params, true);
}
void FramelessQuickHelperPrivate::bringWindowToFront()
@ -483,7 +484,9 @@ void FramelessQuickHelperPrivate::emitSignalForAllInstances(const QByteArray &si
if (!window) {
return;
}
const auto rootObject = (window->contentItem() ? qobject_cast<const QObject *>(window->contentItem()) : qobject_cast<const QObject *>(window));
const auto rootObject = (window->contentItem() ?
qobject_cast<const QObject *>(window->contentItem())
: qobject_cast<const QObject *>(window));
const auto instances = rootObject->findChildren<FramelessQuickHelper *>();
if (instances.isEmpty()) {
return;

View File

@ -23,19 +23,6 @@
*/
#include "framelesshelperwidgets_global.h"
#include "standardtitlebar.h"
#include "standardsystembutton.h"
#include "framelesswidgetshelper.h"
#include "framelesswidget.h"
#include "framelessmainwindow.h"
#include "framelessdialog.h"
#include "widgetssharedhelper_p.h"
#include "standardtitlebar_p.h"
#include "standardsystembutton_p.h"
#include "framelesswidgetshelper_p.h"
#include "framelesswidget_p.h"
#include "framelessmainwindow_p.h"
#include "framelessdialog_p.h"
#include <QtCore/qloggingcategory.h>
FRAMELESSHELPER_BEGIN_NAMESPACE
@ -66,22 +53,6 @@ void initialize()
inited = true;
FramelessHelper::Core::initialize();
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
qRegisterMetaType<StandardTitleBar>();
qRegisterMetaType<StandardSystemButton>();
qRegisterMetaType<FramelessWidgetsHelper>();
qRegisterMetaType<FramelessWidget>();
qRegisterMetaType<FramelessMainWindow>();
qRegisterMetaType<FramelessDialog>();
qRegisterMetaType<WidgetsSharedHelper>();
qRegisterMetaType<StandardTitleBarPrivate>();
qRegisterMetaType<StandardSystemButtonPrivate>();
qRegisterMetaType<FramelessWidgetsHelperPrivate>();
qRegisterMetaType<FramelessWidgetPrivate>();
qRegisterMetaType<FramelessMainWindowPrivate>();
qRegisterMetaType<FramelessDialogPrivate>();
#endif
}
void uninitialize()

View File

@ -32,8 +32,9 @@
#include "framelessdialog_p.h"
#include "widgetssharedhelper_p.h"
#include <FramelessHelper/Core/framelessmanager.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/private/framelesshelpercore_global_p.h>
#include <QtCore/qmutex.h>
#include <QtCore/qhash.h>
#include <QtCore/qtimer.h>
@ -462,7 +463,7 @@ void FramelessWidgetsHelperPrivate::attach()
params.unsetCursor = [window]() -> void { window->unsetCursor(); };
params.getWidgetHandle = [window]() -> QObject * { return window; };
FramelessManager::instance()->addWindow(params);
FramelessManager::instance()->addWindow(&params);
g_widgetsHelper()->mutex.lock();
data->params = params;
@ -762,15 +763,8 @@ void FramelessWidgetsHelperPrivate::moveWindowToDesktopCenter()
if (!m_window) {
return;
}
Utils::moveWindowToDesktopCenter([this]() -> QScreen * {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
return m_window->screen();
#else
return m_window->windowHandle()->screen();
#endif
},
[this]() -> QSize { return m_window->size(); },
[this](const QPoint &pos) -> void { m_window->move(pos); }, true);
const SystemParameters params = getWindowData().params;
Utils::moveWindowToDesktopCenter(&params, true);
}
void FramelessWidgetsHelperPrivate::bringWindowToFront()
@ -801,7 +795,8 @@ void FramelessWidgetsHelperPrivate::showSystemMenu(const QPoint &pos)
const QPoint globalPos = m_window->mapToGlobal(pos);
const QPoint nativePos = Utils::toNativePixels(m_window->windowHandle(), globalPos);
#ifdef Q_OS_WINDOWS
Utils::showSystemMenu(windowId, nativePos, false, [this]() -> bool { return isWindowFixedSize(); });
const SystemParameters params = getWindowData().params;
Utils::showSystemMenu(windowId, nativePos, false, &params);
#elif defined(Q_OS_LINUX)
Utils::openSystemMenu(windowId, nativePos);
#else

View File

@ -24,8 +24,8 @@
#include "standardsystembutton.h"
#include "standardsystembutton_p.h"
#include <FramelessHelper/Core/private/framelessmanager_p.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Core/private/framelessmanager_p.h>
#include <QtCore/qloggingcategory.h>
#include <QtGui/qpainter.h>
#include <QtGui/qevent.h>

View File

@ -23,11 +23,11 @@
*/
#include "widgetssharedhelper_p.h"
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/micamaterial.h>
#include <FramelessHelper/Core/private/micamaterial_p.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Core/windowborderpainter.h>
#include <FramelessHelper/Core/private/framelessconfig_p.h>
#include <FramelessHelper/Core/private/micamaterial_p.h>
#ifdef Q_OS_WINDOWS
# include <FramelessHelper/Core/private/winverhelper_p.h>
#endif // Q_OS_WINDOWS