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

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Oct 4, 2023
1 parent b946809 commit d86f558
Show file tree
Hide file tree
Showing 67 changed files with 1,696 additions and 1,297 deletions.
93 changes: 53 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ project(FramelessHelper
)

include(CMakeDependentOption)
include(cmake/utils.cmake)

# TODO: Use add_feature_info() for every option below? Is it worth doing?
option(FRAMELESSHELPER_BUILD_STATIC "Build FramelessHelper as a static library." OFF)
Expand Down Expand Up @@ -61,27 +62,26 @@ option(FRAMELESSHELPER_NO_TRANSLATION "Don't bundle the I18N translations into t
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)

if(FRAMELESSHELPER_NO_WINDOW AND FRAMELESSHELPER_BUILD_EXAMPLES)
message(WARNING "You can't build the examples when the FramelessWindow class is disabled at the same time!")
set(FRAMELESSHELPER_BUILD_EXAMPLES OFF)
endif()

set(FRAMELESSHELPER_64BIT_POSTFIX "")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(FRAMELESSHELPER_64BIT_POSTFIX "64")
endif()
cmake_dependent_option(FRAMELESSHELPER_NATIVE_IMPL "Use platform native implementation instead of Qt to get best experience." ON WIN32 OFF)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

find_package(QT NAMES Qt6 Qt5 QUIET COMPONENTS Widgets Quick)
find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS Widgets Quick)

include(cmake/utils.cmake)
if(FRAMELESSHELPER_NATIVE_IMPL AND NOT WIN32)
message(WARNING "FRAMELESSHELPER_NATIVE_IMPL currently only supports the Windows platform!")
set(FRAMELESSHELPER_NATIVE_IMPL OFF)
endif()

if(NOT APPLE AND FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD)
message(WARNING "Current OS is not macOS, universal build will be disabled.")
if(FRAMELESSHELPER_NO_WINDOW AND FRAMELESSHELPER_BUILD_EXAMPLES)
message(WARNING "You can't build the examples when the FramelessWindow class is disabled at the same time!")
set(FRAMELESSHELPER_BUILD_EXAMPLES OFF)
endif()

if(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD AND NOT APPLE)
message(WARNING "Universal build is a macOS only feature, it will be disabled on current platform.")
set(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD OFF)
elseif(APPLE AND ((QT_VERSION VERSION_LESS "6.2" AND QT_VERSION VERSION_GREATER_EQUAL "6.0") OR (QT_VERSION VERSION_LESS "5.15.9")))
message(WARNING "Your Qt version ${QT_VERSION} doesn't support universal build, it will be disabled.")
Expand All @@ -94,6 +94,29 @@ endif()

if(FRAMELESSHELPER_ENABLE_VCLTL AND NOT MSVC)
message(WARNING "VC-LTL is only available for the MSVC toolchain.")
set(FRAMELESSHELPER_ENABLE_VCLTL OFF)
endif()

if(FRAMELESSHELPER_ENABLE_YYTHUNKS AND NOT MSVC)
message(WARNING "YY-Thunks is only available for the MSVC toolchain.")
set(FRAMELESSHELPER_ENABLE_YYTHUNKS OFF)
endif()

if(NOT TARGET Qt${QT_VERSION_MAJOR}::Core OR NOT TARGET Qt${QT_VERSION_MAJOR}::Gui)
message(WARNING "Can't find the QtCore and/or QtGui module. Nothing will be built.")
set(FRAMELESSHELPER_BUILD_WIDGETS OFF)
set(FRAMELESSHELPER_BUILD_QUICK OFF)
set(FRAMELESSHELPER_BUILD_EXAMPLES OFF)
endif()

if(FRAMELESSHELPER_BUILD_QUICK AND NOT TARGET Qt${QT_VERSION_MAJOR}::Quick)
message(WARNING "Can't find the QtQuick module. FramelessHelper's QtQuick implementation and the QtQuick demo won't be built.")
set(FRAMELESSHELPER_BUILD_QUICK OFF)
endif()

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

set(FRAMELESSHELPER_LICENSE_HEADER "/*
Expand Down Expand Up @@ -144,25 +167,23 @@ if(MINGW AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(FRAMELESSHELPER_ENABLE_CFGUARD OFF)
endif()

if(MSVC)
if(FRAMELESSHELPER_ENABLE_VCLTL)
include(cmake/VC-LTL.cmake)
if("x${SupportLTL}" STREQUAL "xtrue")
# Make sure we will always overwrite the previous settings.
unset(CMAKE_MSVC_RUNTIME_LIBRARY)
unset(CMAKE_MSVC_RUNTIME_LIBRARY CACHE)
#unset(CMAKE_MSVC_RUNTIME_LIBRARY PARENT_SCOPE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)
endif()
endif()
if(FRAMELESSHELPER_ENABLE_YYTHUNKS)
unset(YYTHUNKS_TARGET_OS)
unset(YYTHUNKS_TARGET_OS CACHE)
#unset(YYTHUNKS_TARGET_OS PARENT_SCOPE)
set(YYTHUNKS_TARGET_OS "WinXP" CACHE STRING "" FORCE)
include(cmake/YY-Thunks.cmake)
if(FRAMELESSHELPER_ENABLE_VCLTL)
include(cmake/VC-LTL.cmake)
if("x${SupportLTL}" STREQUAL "xtrue")
# Make sure we will always overwrite the previous settings.
unset(CMAKE_MSVC_RUNTIME_LIBRARY)
unset(CMAKE_MSVC_RUNTIME_LIBRARY CACHE)
#unset(CMAKE_MSVC_RUNTIME_LIBRARY PARENT_SCOPE)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" CACHE STRING "" FORCE)
endif()
endif()
if(FRAMELESSHELPER_ENABLE_YYTHUNKS)
unset(YYTHUNKS_TARGET_OS)
unset(YYTHUNKS_TARGET_OS CACHE)
#unset(YYTHUNKS_TARGET_OS PARENT_SCOPE)
set(YYTHUNKS_TARGET_OS "WinXP" CACHE STRING "" FORCE)
include(cmake/YY-Thunks.cmake)
endif()

set(__extra_flags "")
if(FRAMELESSHELPER_NO_INSTALL)
Expand All @@ -175,11 +196,6 @@ prepare_package_export(
)
unset(__extra_flags)

if(FRAMELESSHELPER_BUILD_QUICK AND NOT TARGET Qt${QT_VERSION_MAJOR}::Quick)
message(WARNING "Can't find the QtQuick module. FramelessHelper's QtQuick implementation and the QtQuick demo won't be built.")
set(FRAMELESSHELPER_BUILD_QUICK OFF)
endif()

set(FRAMELESSHELPER_VERSION_FILE "${PROJECT_BINARY_DIR}/framelesshelper.version")
generate_project_version(
PATH "${FRAMELESSHELPER_VERSION_FILE}"
Expand All @@ -202,14 +218,11 @@ add_project_config(KEY "translation" CONDITION NOT FRAMELESSHELPER_NO_TRANSLATIO
add_project_config(KEY "mica_material" CONDITION NOT FRAMELESSHELPER_NO_MICA_MATERIAL)
add_project_config(KEY "border_painter" CONDITION NOT FRAMELESSHELPER_NO_BORDER_PAINTER)
add_project_config(KEY "system_button" CONDITION NOT FRAMELESSHELPER_NO_SYSTEM_BUTTON)
add_project_config(KEY "native_impl" CONDITION FRAMELESSHELPER_NATIVE_IMPL)
generate_project_config(PATH "${FRAMELESSHELPER_CONFIG_FILE}")

if(TARGET Qt${QT_VERSION_MAJOR}::Core AND TARGET Qt${QT_VERSION_MAJOR}::Gui)
if(FRAMELESSHELPER_BUILD_WIDGETS OR FRAMELESSHELPER_BUILD_QUICK)
add_subdirectory(src)
else()
message(WARNING "Can't find the QtCore and QtGui module. Nothing will be built.")
set(FRAMELESSHELPER_BUILD_WIDGETS OFF)
set(FRAMELESSHELPER_BUILD_EXAMPLES OFF)
endif()

if(FRAMELESSHELPER_BUILD_EXAMPLES)
Expand Down
47 changes: 47 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@echo off
title Building FramelessHelper ...
setlocal
cls
set __vs_bat=%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
if not exist "%__vs_bat%" set __vs_bat=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
if not exist "%__vs_bat%" set __vs_bat=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat
if not exist "%__vs_bat%" set __vs_bat=%ProgramFiles(x86)%\Microsoft Visual Studio\2015\Community\VC\Auxiliary\Build\vcvars64.bat
if not exist "%__vs_bat%" (
echo Cannot find a valid Visual Studio toolchain!
echo Please install at least Visual Studio 2015 to the default location
echo and install the English language pack at the same time.
echo If you want to use clang-cl or MinGW to build this project, please
echo make sure you have added their directory to your PATH environment
echo variable.
echo Press the ENTER key to continue, or close this window directly.
pause
) else (
call "%__vs_bat%"
)
cmake --version
echo ninja build
ninja --version
cd /d "%~dp0"
if exist build.user.bat call build.user.bat
if not defined CC set CC=cl.exe
if not defined CXX set CXX=cl.exe
if not defined QTDIR set QTDIR=%SystemDrive%\Qt\6.6.0\msvc2019_64
echo CC=%CC%
echo CXX=%CXX%
echo QTDIR=%QTDIR%
if exist build rd /s /q build
md build
cd build
md cmake
cd cmake
cmake -DCMAKE_C_COMPILER="%CC%" -DCMAKE_CXX_COMPILER="%CXX%" -DCMAKE_PREFIX_PATH="%QTDIR%" -DCMAKE_INSTALL_PREFIX="%~dp0build\install" -DCMAKE_CONFIGURATION_TYPES=Release;Debug -G"Ninja Multi-Config" -DFRAMELESSHELPER_ENABLE_VCLTL=ON -DFRAMELESSHELPER_ENABLE_YYTHUNKS=ON -DFRAMELESSHELPER_ENABLE_SPECTRE=ON -DFRAMELESSHELPER_ENABLE_EHCONTGUARD=ON -DFRAMELESSHELPER_ENABLE_INTELCET=ON -DFRAMELESSHELPER_ENABLE_INTELJCC=ON -DFRAMELESSHELPER_ENABLE_CFGUARD=ON -DFRAMELESSHELPER_FORCE_LTO=ON "%~dp0"
cmake --build . --target all --config Release --parallel
cmake --build . --target all --config Debug --parallel
cmake --install . --config Release --strip
cmake --install . --config Debug
goto fin
:fin
endlocal
cd /d "%~dp0"
pause
exit /b 0
37 changes: 0 additions & 37 deletions build/msvc.bat

This file was deleted.

8 changes: 1 addition & 7 deletions include/FramelessHelper/Core/chromepalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,10 @@
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)
FRAMELESSHELPER_PUBLIC_QT_CLASS(ChromePalette)

Q_PROPERTY(QColor titleBarActiveBackgroundColor READ titleBarActiveBackgroundColor
WRITE setTitleBarActiveBackgroundColor RESET resetTitleBarActiveBackgroundColor
Expand Down Expand Up @@ -120,9 +117,6 @@ public Q_SLOTS:
void closeButtonPressColorChanged();
void titleBarColorChanged();
void chromeButtonColorChanged();

private:
QScopedPointer<ChromePalettePrivate> d_ptr;
};

FRAMELESSHELPER_END_NAMESPACE
Expand Down
14 changes: 8 additions & 6 deletions include/FramelessHelper/Core/framelesshelper_qt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,27 @@

#include <FramelessHelper/Core/framelesshelpercore_global.h>

FRAMELESSHELPER_BEGIN_NAMESPACE
#if !FRAMELESSHELPER_CONFIG(native_impl)

struct SystemParameters;
FRAMELESSHELPER_BEGIN_NAMESPACE

class FramelessHelperQtPrivate;
class FRAMELESSHELPER_CORE_API FramelessHelperQt : public QObject
{
Q_OBJECT
FRAMELESSHELPER_CLASS_INFO
Q_DISABLE_COPY_MOVE(FramelessHelperQt)
FRAMELESSHELPER_PUBLIC_QT_CLASS(FramelessHelperQt)

public:
explicit FramelessHelperQt(QObject *parent = nullptr);
~FramelessHelperQt() override;

static void addWindow(const SystemParameters *params);
static void removeWindow(const WId windowId);
static void addWindow(const QObject *window);
static void removeWindow(const QObject *window);

protected:
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
};

FRAMELESSHELPER_END_NAMESPACE

#endif // !native_impl
12 changes: 7 additions & 5 deletions include/FramelessHelper/Core/framelesshelper_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,26 @@

#ifdef Q_OS_WINDOWS

FRAMELESSHELPER_BEGIN_NAMESPACE
#if FRAMELESSHELPER_CONFIG(native_impl)

struct SystemParameters;
FRAMELESSHELPER_BEGIN_NAMESPACE

class FRAMELESSHELPER_CORE_API FramelessHelperWin : public QAbstractNativeEventFilter
{
Q_DISABLE_COPY_MOVE(FramelessHelperWin)
FRAMELESSHELPER_CLASS(FramelessHelperWin)

public:
explicit FramelessHelperWin();
~FramelessHelperWin() override;

static void addWindow(const SystemParameters *params);
static void removeWindow(const WId windowId);
static void addWindow(const QObject *window);
static void removeWindow(const QObject *window);

Q_NODISCARD bool nativeEventFilter(const QByteArray &eventType, void *message, QT_NATIVE_EVENT_RESULT_TYPE *result) override;
};

FRAMELESSHELPER_END_NAMESPACE

#endif // native_impl

#endif // Q_OS_WINDOWS
Loading

0 comments on commit d86f558

Please sign in to comment.