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

Commit

Permalink
large refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Aug 27, 2023
1 parent 2db8298 commit 6abb636
Show file tree
Hide file tree
Showing 97 changed files with 1,525 additions and 1,071 deletions.
26 changes: 23 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ option(FRAMELESSHELPER_EXAMPLES_STANDALONE "Build the demo projects as standalon
cmake_dependent_option(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD "macOS only: build universal library/example for Mac." ON APPLE OFF)
option(FRAMELESSHELPER_FORCE_LTO "Force enable LTO/LTCG even when building static libraries." OFF)
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON)
option(FRAMELESSHELPER_NO_WINDOW "Disable the pre-defined FramelessWindow wrapper class." OFF)
option(FRAMELESSHELPER_NO_TITLEBAR "Disable the pre-defined StandardTitleBar control." OFF)
option(FRAMELESSHELPER_NO_TRANSLATION "Don't bundle the I18N translations into the library." OFF)
option(FRAMELESSHELPER_NO_MICA_MATERIAL "Disable the cross-platform homemade Mica Material." OFF)
option(FRAMELESSHELPER_NO_BORDER_PAINTER "Disable the cross-platform window frame border painter." OFF)
option(FRAMELESSHELPER_NO_SYSTEM_BUTTON "Disable the pre-defined StandardSystemButton control." OFF)

set(PROJECT_VERSION_HEX "0x00000000")
math(EXPR PROJECT_VERSION_HEX "((${PROJECT_VERSION_MAJOR} & 0xff) << 24) | ((${PROJECT_VERSION_MINOR} & 0xff) << 16) | ((${PROJECT_VERSION_PATCH} & 0xff) << 8)" OUTPUT_FORMAT HEXADECIMAL)

set(FRAMELESSHELPER_64BIT_POSTFIX "")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FRAMELESSHELPER_64BIT_POSTFIX "64")
endif()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
Expand All @@ -80,7 +94,7 @@ if(FRAMELESSHELPER_ENABLE_VCLTL AND NOT MSVC)
message(WARNING "VC-LTL is only available for the MSVC toolchain.")
endif()

set(__extra_flags)
set(__extra_flags "")
if(NOT FRAMELESSHELPER_BUILD_STATIC)
list(APPEND __extra_flags ENABLE_LTO)
endif()
Expand Down Expand Up @@ -130,7 +144,7 @@ if(MSVC)
endif()
endif()

set(__extra_flags)
set(__extra_flags "")
if(FRAMELESSHELPER_NO_INSTALL)
list(APPEND __extra_flags NO_INSTALL)
endif()
Expand Down Expand Up @@ -158,7 +172,7 @@ if(FRAMELESSHELPER_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if(NOT FRAMELESSHELPER_NO_INSTALL)
if(WIN32 AND NOT FRAMELESSHELPER_NO_INSTALL)
install(FILES "msbuild/FramelessHelper.props" DESTINATION ".")
endif()

Expand Down Expand Up @@ -234,5 +248,11 @@ if(NOT FRAMELESSHELPER_NO_SUMMARY)
message("[macOS]: Build universal library/example: ${FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD}")
message("Force enable LTO: ${FRAMELESSHELPER_FORCE_LTO}")
message("Make output reproducible: ${FRAMELESSHELPER_REPRODUCIBLE_OUTPUT}")
message("Disable the FramelessWindow class (to reduce file size): ${FRAMELESSHELPER_NO_WINDOW}")
message("Disable the StandardTitleBar class (to reduce file size): ${FRAMELESSHELPER_NO_TITLEBAR}")
message("Don't embed the I18N resources (to reduce file size): ${FRAMELESSHELPER_NO_TRANSLATION}")
message("Disable the MicaMaterial class (to reduce file size): ${FRAMELESSHELPER_NO_MICA_MATERIAL}")
message("Disable the WindowBorderPainter class (to reduce file size): ${FRAMELESSHELPER_NO_BORDER_PAINTER}")
message("Disable the StandardSystemButton class (to reduce file size): ${FRAMELESSHELPER_NO_SYSTEM_BUTTON}")
message("-----------------------------------------------------------------")
endif()
2 changes: 1 addition & 1 deletion cmake
Submodule cmake updated 1 files
+2 −2 utils.cmake
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/chromepalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

#include <FramelessHelper/Core/framelesshelpercore_global.h>

#if FRAMELESSHELPER_CONFIG(titlebar)

FRAMELESSHELPER_BEGIN_NAMESPACE

class ChromePalettePrivate;

class FRAMELESSHELPER_CORE_API ChromePalette : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DECLARE_PRIVATE(ChromePalette)
Q_DISABLE_COPY_MOVE(ChromePalette)

Expand Down Expand Up @@ -123,3 +126,5 @@ public Q_SLOTS:
};

FRAMELESSHELPER_END_NAMESPACE

#endif
1 change: 1 addition & 0 deletions include/FramelessHelper/Core/framelesshelper_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct SystemParameters;
class FRAMELESSHELPER_CORE_API FramelessHelperQt : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(FramelessHelperQt)

public:
Expand Down
4 changes: 4 additions & 0 deletions include/FramelessHelper/Core/framelesshelper_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <QtCore/qabstractnativeeventfilter.h>

#ifdef Q_OS_WINDOWS

FRAMELESSHELPER_BEGIN_NAMESPACE

struct SystemParameters;
Expand All @@ -46,3 +48,5 @@ class FRAMELESSHELPER_CORE_API FramelessHelperWin : public QAbstractNativeEventF
};

FRAMELESSHELPER_END_NAMESPACE

#endif // Q_OS_WINDOWS
77 changes: 70 additions & 7 deletions include/FramelessHelper/Core/framelesshelpercore_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#pragma once

#include "framelesshelper.config"
#include <QtCore/qglobal.h>
#include <QtCore/qmath.h>
#include <QtCore/qpoint.h>
Expand Down Expand Up @@ -165,6 +166,41 @@ QT_END_NAMESPACE
} while (false)
#endif

#ifndef FRAMELESSHELPER_QUOTE
# define FRAMELESSHELPER_QUOTE(x) #x
#endif

#ifndef FRAMELESSHELPER_QUOTE2
# define FRAMELESSHELPER_QUOTE2(x) FRAMELESSHELPER_QUOTE(x)
#endif

#ifndef FRAMELESSHELPER_CONCAT
# define FRAMELESSHELPER_CONCAT(a, b) a##b
#endif

#ifndef FRAMELESSHELPER_CONCAT2
# define FRAMELESSHELPER_CONCAT2(a, b) FRAMELESSHELPER_CONCAT(a, b)
#endif

/*
The FRAMELESSHELPER_CONFIG macro implements a safe compile time check for features of FramelessHelper.
Features can be in three states:
0 or undefined: This will lead to a compile error when testing for it
-1: The feature is not available
1: The feature is available
*/
#ifndef FRAMELESSHELPER_CONFIG
# define FRAMELESSHELPER_CONFIG(feature) ((1 / FRAMELESSHELPER_FEATURE_##feature) == 1)
#endif

#ifndef FRAMELESSHELPER_REQUIRE_CONFIG
# define FRAMELESSHELPER_REQUIRE_CONFIG(feature) static_assert(FRAMELESSHELPER_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " is not available!")
#endif

#ifndef FRAMELESSHELPER_CLASS_INFO
# define FRAMELESSHELPER_CLASS_INFO Q_CLASSINFO("__FRAMELESSHELPER__", FRAMELESSHELPER_QUOTE2(__FRAMELESSHELPER__))
#endif

#ifndef FRAMELESSHELPER_BYTEARRAY_CONSTANT2
# define FRAMELESSHELPER_BYTEARRAY_CONSTANT2(name, ba) \
[[maybe_unused]] static constexpr const auto k##name = FRAMELESSHELPER_BYTEARRAY(ba);
Expand Down Expand Up @@ -217,11 +253,12 @@ QT_END_NAMESPACE
}
#endif

#ifndef FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE
#if FRAMELESSHELPER_CONFIG(bundle_resource)
// Call this function in your main() function if you are using FramelessHelper as a static library,
// it can make sure the resources bundled in the static library are correctly initialized.
// NOTE: This function is intentionally not inside any namespaces.
FRAMELESSHELPER_CORE_API void framelesshelpercore_initResource();
FRAMELESSHELPER_CORE_API void FramelessHelperCoreInitResource();
inline void framelesshelpercore_initResource() { FramelessHelperCoreInitResource(); }
#endif // FRAMELESSHELPER_CORE_NO_BUNDLE_RESOURCE

FRAMELESSHELPER_BEGIN_NAMESPACE
Expand Down Expand Up @@ -474,17 +511,43 @@ struct Dpi
{
return !operator==(lhs, rhs);
}

[[nodiscard]] friend constexpr bool operator>(const Dpi &lhs, const Dpi &rhs) noexcept
{
return ((lhs.x * lhs.y) > (rhs.x * rhs.y));
}

[[nodiscard]] friend constexpr bool operator>=(const Dpi &lhs, const Dpi &rhs) noexcept
{
return (operator>(lhs, rhs) || operator==(lhs, rhs));
}

[[nodiscard]] friend constexpr bool operator<(const Dpi &lhs, const Dpi &rhs) noexcept
{
return (operator!=(lhs, rhs) && !operator>(lhs, rhs));
}

[[nodiscard]] friend constexpr bool operator<=(const Dpi &lhs, const Dpi &rhs) noexcept
{
return (operator<(lhs, rhs) || operator==(lhs, rhs));
}
};

} // namespace Global

FRAMELESSHELPER_CORE_API void FramelessHelperCoreInitialize();
FRAMELESSHELPER_CORE_API void FramelessHelperCoreUninitialize();
[[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo FramelessHelperVersion();
FRAMELESSHELPER_CORE_API void FramelessHelperEnableThemeAware();
FRAMELESSHELPER_CORE_API void FramelessHelperPrintLogo();

namespace FramelessHelper::Core
{
FRAMELESSHELPER_CORE_API void initialize();
FRAMELESSHELPER_CORE_API void uninitialize();
[[nodiscard]] FRAMELESSHELPER_CORE_API Global::VersionInfo version();
FRAMELESSHELPER_CORE_API void setApplicationOSThemeAware();
FRAMELESSHELPER_CORE_API void outputLogo();
inline void initialize() { FramelessHelperCoreInitialize(); }
inline void uninitialize() { FramelessHelperCoreUninitialize(); }
[[nodiscard]] inline Global::VersionInfo version() { return FramelessHelperVersion(); }
inline void setApplicationOSThemeAware() { FramelessHelperEnableThemeAware(); }
inline void outputLogo() { FramelessHelperPrintLogo(); }
} // namespace FramelessHelper::Core

FRAMELESSHELPER_END_NAMESPACE
Expand Down
1 change: 1 addition & 0 deletions include/FramelessHelper/Core/framelessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FramelessManagerPrivate;
class FRAMELESSHELPER_CORE_API FramelessManager : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DECLARE_PRIVATE(FramelessManager)
Q_DISABLE_COPY_MOVE(FramelessManager)
Q_PROPERTY(Global::SystemTheme systemTheme READ systemTheme WRITE setOverrideTheme NOTIFY systemThemeChanged FINAL)
Expand Down
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/micamaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@

#include <FramelessHelper/Core/framelesshelpercore_global.h>

#if FRAMELESSHELPER_CONFIG(mica_material)

FRAMELESSHELPER_BEGIN_NAMESPACE

class MicaMaterialPrivate;

class FRAMELESSHELPER_CORE_API MicaMaterial : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(MicaMaterial)
Q_DECLARE_PRIVATE(MicaMaterial)

Expand Down Expand Up @@ -83,3 +86,5 @@ public Q_SLOTS:
};

FRAMELESSHELPER_END_NAMESPACE

#endif
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/private/chromepalette_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <optional>

#if FRAMELESSHELPER_CONFIG(titlebar)

FRAMELESSHELPER_BEGIN_NAMESPACE

class ChromePalette;

class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DECLARE_PUBLIC(ChromePalette)
Q_DISABLE_COPY_MOVE(ChromePalettePrivate)

Expand Down Expand Up @@ -72,3 +75,5 @@ class FRAMELESSHELPER_CORE_API ChromePalettePrivate : public QObject
};

FRAMELESSHELPER_END_NAMESPACE

#endif
1 change: 1 addition & 0 deletions include/FramelessHelper/Core/private/framelessconfig_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
class FRAMELESSHELPER_CORE_API FramelessConfig : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(FramelessConfig)

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ 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()>;
Expand Down Expand Up @@ -102,9 +99,6 @@ 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

#define DECLARE_SIZE_COMPARE_OPERATORS(Type1, Type2) \
Expand Down
1 change: 1 addition & 0 deletions include/FramelessHelper/Core/private/framelessmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FramelessManager;
class FRAMELESSHELPER_CORE_API FramelessManagerPrivate : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DECLARE_PUBLIC(FramelessManager)
Q_DISABLE_COPY_MOVE(FramelessManagerPrivate)

Expand Down
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/private/micamaterial_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <QtGui/qbrush.h>

#if FRAMELESSHELPER_CONFIG(mica_material)

FRAMELESSHELPER_BEGIN_NAMESPACE

class MicaMaterial;

class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(MicaMaterialPrivate)
Q_DECLARE_PUBLIC(MicaMaterial)

Expand Down Expand Up @@ -69,3 +72,5 @@ class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject
};

FRAMELESSHELPER_END_NAMESPACE

#endif
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/private/registrykey_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QtCore/qvariant.h>
#include <optional>

#ifdef Q_OS_WINDOWS

#ifndef REGISTRYKEY_FORCE_QSETTINGS
# define REGISTRYKEY_FORCE_QSETTINGS (0)
#endif // REGISTRYKEY_FORCE_QSETTINGS
Expand Down Expand Up @@ -58,6 +60,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
class FRAMELESSHELPER_CORE_API RegistryKey : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(RegistryKey)

public:
Expand Down Expand Up @@ -91,3 +94,5 @@ class FRAMELESSHELPER_CORE_API RegistryKey : public QObject
};

FRAMELESSHELPER_END_NAMESPACE

#endif // Q_OS_WINDOWS
3 changes: 2 additions & 1 deletion include/FramelessHelper/Core/private/sysapiloader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
class FRAMELESSHELPER_CORE_API SysApiLoader : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(SysApiLoader)

public:
Expand Down Expand Up @@ -86,7 +87,7 @@ FRAMELESSHELPER_END_NAMESPACE
# define API_NT_AVAILABLE(func) API_AVAILABLE(ntdll, func)
#endif // Q_OS_WINDOWS

#ifdef Q_OS_LINUX
#if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID))
# define API_XLIB_AVAILABLE(func) API_AVAILABLE(libX11, func)
# define API_XCB_AVAILABLE(func) API_AVAILABLE(libxcb, func)
# define API_GTK_AVAILABLE(func) API_AVAILABLE(libgtk, func)
Expand Down
5 changes: 5 additions & 0 deletions include/FramelessHelper/Core/private/windowborderpainter_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@
#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <optional>

#if FRAMELESSHELPER_CONFIG(border_painter)

FRAMELESSHELPER_BEGIN_NAMESPACE

class WindowBorderPainter;

class FRAMELESSHELPER_CORE_API WindowBorderPainterPrivate : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DECLARE_PUBLIC(WindowBorderPainter)
Q_DISABLE_COPY_MOVE(WindowBorderPainterPrivate)

Expand All @@ -52,3 +55,5 @@ class FRAMELESSHELPER_CORE_API WindowBorderPainterPrivate : public QObject
};

FRAMELESSHELPER_END_NAMESPACE

#endif
Loading

0 comments on commit 6abb636

Please sign in to comment.