diff --git a/CMakeLists.txt b/CMakeLists.txt index b3d074d..41878aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,9 @@ option(INDEPENDENT_BUILD "build self." OFF) option(UNIT_TEST "do unit test" OFF) if(INDEPENDENT_BUILD) + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(KYLIN_WITH_FLUENT ON) if(WIN32) set(Projects_ROOT E:/Projects) @@ -15,6 +18,11 @@ if(INDEPENDENT_BUILD) add_compile_definitions( BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10 ) + + set(OpenSSL_ROOT D:/Qt/Tools/OpenSSLv3/Win_x64) + set(OPENSSL_INCLUDE_DIR ${OpenSSL_ROOT}/include) + set(OpenSSL_LIBRARY_DIRS ${OpenSSL_ROOT}/lib) + set(OpenSSL_LIBRARIES libssl libcrypto) else() execute_process( COMMAND sh -c "echo $HOME" @@ -26,6 +34,8 @@ if(INDEPENDENT_BUILD) set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0) set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include) endif() + option(Boost_USE_STATIC_LIBS OFF) + add_subdirectory(Examples) endif() diff --git a/Fluent/Frameless.cpp b/Fluent/Frameless.cpp index 06d3f38..56bde84 100644 --- a/Fluent/Frameless.cpp +++ b/Fluent/Frameless.cpp @@ -6,6 +6,29 @@ #include #ifdef Q_OS_WIN +#include +#include +#include + +struct ACCENT_POLICY { + DWORD dwAccentState; + DWORD dwAccentFlags; + DWORD dwGradientColor; // #AABBGGRR + DWORD dwAnimationId; +}; +using PACCENT_POLICY = ACCENT_POLICY *; +struct WINDOWCOMPOSITIONATTRIBDATA { + WINDOWCOMPOSITIONATTRIB Attrib; + PVOID pvData; + SIZE_T cbData; +}; +using PWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA *; + +typedef HRESULT (WINAPI *DwmSetWindowAttributeFunc)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute); +typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaFunc)(HWND hwnd, const MARGINS *pMarInset); +typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL *pfEnabled); +typedef HRESULT (WINAPI *DwmEnableBlurBehindWindowFunc)(HWND hWnd, const DWM_BLURBEHIND *pBlurBehind); +typedef BOOL (WINAPI *SetWindowCompositionAttributeFunc)(HWND hwnd, const WINDOWCOMPOSITIONATTRIBDATA *); static DwmSetWindowAttributeFunc pDwmSetWindowAttribute = nullptr; static DwmExtendFrameIntoClientAreaFunc pDwmExtendFrameIntoClientArea = nullptr; @@ -295,37 +318,37 @@ void Frameless::componentComplete() { } else { availableEffects({"dwm-blur","normal"}); } - if (!_effect.isEmpty() && _useSystemEffect) { - effective(setWindowEffect(hwnd, _effect, true)); + if (!m_effect.isEmpty() && m_useSystemEffect) { + effective(setWindowEffect(hwnd, m_effect, true)); if (effective()) { - _currentEffect = effect(); + m_currentEffect = effect(); } } connect(this, &Frameless::effectChanged, this, [hwnd, this] { - if (effect() == _currentEffect) { + if (effect() == m_currentEffect) { return; } if (effective()) { - setWindowEffect(hwnd, _currentEffect, false); + setWindowEffect(hwnd, m_currentEffect, false); } effective(setWindowEffect(hwnd, effect(), true)); if (effective()) { - _currentEffect = effect(); - _useSystemEffect = true; + m_currentEffect = effect(); + m_useSystemEffect = true; } else { - _effect = "normal"; - _currentEffect = "normal"; - _useSystemEffect = false; + m_effect = "normal"; + m_currentEffect = "normal"; + m_useSystemEffect = false; } }); connect(this, &Frameless::useSystemEffectChanged, this, [this] { - if (!_useSystemEffect) { + if (!m_useSystemEffect) { effect("normal"); } }); connect(this, &Frameless::isDarkModeChanged, this, [hwnd, this] { - if (effective() && !_currentEffect.isEmpty() && _currentEffect != "normal") { - setWindowDarkMode(hwnd, _isDarkMode); + if (effective() && !m_currentEffect.isEmpty() && m_currentEffect != "normal") { + setWindowDarkMode(hwnd, m_isDarkMode); } }); #endif @@ -361,7 +384,7 @@ void Frameless::componentComplete() { # if (QT_VERSION == QT_VERSION_CHECK(6, 7, 2)) style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU); # endif - if (_fixSize) { + if (m_fixSize) { ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);; for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) { connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] { @@ -406,7 +429,7 @@ void Frameless::componentComplete() { return false; } const quint64 wid = reinterpret_cast(hwnd); - if (wid != _current) { + if (wid != m_current) { return false; } const auto uMsg = msg->message; @@ -431,7 +454,7 @@ void Frameless::componentComplete() { *result = WVR_REDRAW; return true; } else if (uMsg == WM_NCHITTEST) { - if (_isWindows11OrGreater) { + if (m_isWindows11OrGreater) { if (_hitMaximizeButton()) { if (*result == HTNOWHERE) { *result = HTZOOM; @@ -450,12 +473,12 @@ void Frameless::componentComplete() { ::GetClientRect(hwnd, &clientRect); auto clientWidth = clientRect.right - clientRect.left; auto clientHeight = clientRect.bottom - clientRect.top; - bool left = nativeLocalPos.x < _margins; - bool right = nativeLocalPos.x > clientWidth - _margins; - bool top = nativeLocalPos.y < _margins; - bool bottom = nativeLocalPos.y > clientHeight - _margins; + bool left = nativeLocalPos.x < m_margins; + bool right = nativeLocalPos.x > clientWidth - m_margins; + bool top = nativeLocalPos.y < m_margins; + bool bottom = nativeLocalPos.y > clientHeight - m_margins; *result = 0; - if (!_fixSize && !_isFullScreen() && !_isMaximized()) { + if (!m_fixSize && !_isFullScreen() && !_isMaximized()) { if (left && top) { *result = HTTOPLEFT; } else if (left && bottom) { @@ -488,21 +511,21 @@ void Frameless::componentComplete() { return false; } else if (uMsg == WM_NCACTIVATE) { *result = TRUE; - if (effective() || (!effect().isEmpty() && _currentEffect!="normal")) { + if (effective() || (!effect().isEmpty() && m_currentEffect != "normal")) { return false; } return true; - } else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) { + } else if (m_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) { if (_hitMaximizeButton()) { QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - QGuiApplication::sendEvent(_maximizeButton, &event); + QGuiApplication::sendEvent(m_maximizeButton, &event); _setMaximizePressed(true); return true; } - } else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP)) { + } else if (m_isWindows11OrGreater && (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP)) { if (_hitMaximizeButton()) { QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); - QGuiApplication::sendEvent(_maximizeButton, &event); + QGuiApplication::sendEvent(m_maximizeButton, &event); _setMaximizePressed(false); return true; } @@ -517,7 +540,7 @@ void Frameless::componentComplete() { const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0)); if (altPressed && spacePressed) { auto pos = window()->position(); - _showSystemMenu(QPoint(pos.x(), qRound(pos.y() + _appbar->height()))); + _showSystemMenu(QPoint(pos.x(), qRound(pos.y() + m_appBar->height()))); } } else if (uMsg == WM_SYSCOMMAND) { if (wParam == SC_MINIMIZE) { @@ -566,7 +589,7 @@ void Frameless::_showSystemMenu(QPoint point) { ::EnableMenuItem(hMenu, SC_MOVE, MFS_ENABLED); ::EnableMenuItem(hMenu, SC_RESTORE, MFS_DISABLED); } - if (!_fixSize && !_isMaximized() && !_isFullScreen()) { + if (!m_fixSize && !_isMaximized() && !_isFullScreen()) { ::EnableMenuItem(hMenu, SC_SIZE, MFS_ENABLED); ::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_ENABLED); } else { diff --git a/Fluent/Frameless.h b/Fluent/Frameless.h index 69420e9..033445e 100644 --- a/Fluent/Frameless.h +++ b/Fluent/Frameless.h @@ -9,12 +9,6 @@ #ifdef Q_OS_WIN -#pragma comment (lib, "user32.lib") -#pragma comment (lib, "dwmapi.lib") - -#include -#include -#include enum _DWM_SYSTEMBACKDROP_TYPE { _DWMSBT_AUTO, // [Default] Let DWM automatically decide the system-drawn backdrop for this // window. @@ -76,26 +70,6 @@ enum ACCENT_FLAG { ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY = 482 }; -struct ACCENT_POLICY { - DWORD dwAccentState; - DWORD dwAccentFlags; - DWORD dwGradientColor; // #AABBGGRR - DWORD dwAnimationId; -}; -using PACCENT_POLICY = ACCENT_POLICY *; -struct WINDOWCOMPOSITIONATTRIBDATA { - WINDOWCOMPOSITIONATTRIB Attrib; - PVOID pvData; - SIZE_T cbData; -}; -using PWINDOWCOMPOSITIONATTRIBDATA = WINDOWCOMPOSITIONATTRIBDATA *; - -typedef HRESULT (WINAPI *DwmSetWindowAttributeFunc)(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute); -typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaFunc)(HWND hwnd, const MARGINS *pMarInset); -typedef HRESULT (WINAPI *DwmIsCompositionEnabledFunc)(BOOL *pfEnabled); -typedef HRESULT (WINAPI *DwmEnableBlurBehindWindowFunc)(HWND hWnd, const DWM_BLURBEHIND *pBlurBehind); -typedef BOOL (WINAPI *SetWindowCompositionAttributeFunc)(HWND hwnd, const WINDOWCOMPOSITIONATTRIBDATA *); - #endif #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))