adapt windows.
This commit is contained in:
parent
578a764ec0
commit
6c2476a671
@ -6,6 +6,9 @@ option(INDEPENDENT_BUILD "build self." OFF)
|
|||||||
option(UNIT_TEST "do unit test" OFF)
|
option(UNIT_TEST "do unit test" OFF)
|
||||||
|
|
||||||
if(INDEPENDENT_BUILD)
|
if(INDEPENDENT_BUILD)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
set(KYLIN_WITH_FLUENT ON)
|
set(KYLIN_WITH_FLUENT ON)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(Projects_ROOT E:/Projects)
|
set(Projects_ROOT E:/Projects)
|
||||||
@ -15,6 +18,11 @@ if(INDEPENDENT_BUILD)
|
|||||||
add_compile_definitions(
|
add_compile_definitions(
|
||||||
BOOST_USE_WINAPI_VERSION=BOOST_WINAPI_VERSION_WIN10
|
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()
|
else()
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND sh -c "echo $HOME"
|
COMMAND sh -c "echo $HOME"
|
||||||
@ -26,6 +34,8 @@ if(INDEPENDENT_BUILD)
|
|||||||
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0)
|
set(BOOST_ROOT ${Libraries_ROOT}/boost_1_86_0)
|
||||||
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include)
|
set(Boost_INCLUDE_DIR ${BOOST_ROOT}/include)
|
||||||
endif()
|
endif()
|
||||||
|
option(Boost_USE_STATIC_LIBS OFF)
|
||||||
|
|
||||||
add_subdirectory(Examples)
|
add_subdirectory(Examples)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
@ -6,6 +6,29 @@
|
|||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
#include <dwmapi.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <windowsx.h>
|
||||||
|
|
||||||
|
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 DwmSetWindowAttributeFunc pDwmSetWindowAttribute = nullptr;
|
||||||
static DwmExtendFrameIntoClientAreaFunc pDwmExtendFrameIntoClientArea = nullptr;
|
static DwmExtendFrameIntoClientAreaFunc pDwmExtendFrameIntoClientArea = nullptr;
|
||||||
@ -295,37 +318,37 @@ void Frameless::componentComplete() {
|
|||||||
} else {
|
} else {
|
||||||
availableEffects({"dwm-blur","normal"});
|
availableEffects({"dwm-blur","normal"});
|
||||||
}
|
}
|
||||||
if (!_effect.isEmpty() && _useSystemEffect) {
|
if (!m_effect.isEmpty() && m_useSystemEffect) {
|
||||||
effective(setWindowEffect(hwnd, _effect, true));
|
effective(setWindowEffect(hwnd, m_effect, true));
|
||||||
if (effective()) {
|
if (effective()) {
|
||||||
_currentEffect = effect();
|
m_currentEffect = effect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(this, &Frameless::effectChanged, this, [hwnd, this] {
|
connect(this, &Frameless::effectChanged, this, [hwnd, this] {
|
||||||
if (effect() == _currentEffect) {
|
if (effect() == m_currentEffect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (effective()) {
|
if (effective()) {
|
||||||
setWindowEffect(hwnd, _currentEffect, false);
|
setWindowEffect(hwnd, m_currentEffect, false);
|
||||||
}
|
}
|
||||||
effective(setWindowEffect(hwnd, effect(), true));
|
effective(setWindowEffect(hwnd, effect(), true));
|
||||||
if (effective()) {
|
if (effective()) {
|
||||||
_currentEffect = effect();
|
m_currentEffect = effect();
|
||||||
_useSystemEffect = true;
|
m_useSystemEffect = true;
|
||||||
} else {
|
} else {
|
||||||
_effect = "normal";
|
m_effect = "normal";
|
||||||
_currentEffect = "normal";
|
m_currentEffect = "normal";
|
||||||
_useSystemEffect = false;
|
m_useSystemEffect = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(this, &Frameless::useSystemEffectChanged, this, [this] {
|
connect(this, &Frameless::useSystemEffectChanged, this, [this] {
|
||||||
if (!_useSystemEffect) {
|
if (!m_useSystemEffect) {
|
||||||
effect("normal");
|
effect("normal");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(this, &Frameless::isDarkModeChanged, this, [hwnd, this] {
|
connect(this, &Frameless::isDarkModeChanged, this, [hwnd, this] {
|
||||||
if (effective() && !_currentEffect.isEmpty() && _currentEffect != "normal") {
|
if (effective() && !m_currentEffect.isEmpty() && m_currentEffect != "normal") {
|
||||||
setWindowDarkMode(hwnd, _isDarkMode);
|
setWindowDarkMode(hwnd, m_isDarkMode);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
@ -361,7 +384,7 @@ void Frameless::componentComplete() {
|
|||||||
# if (QT_VERSION == QT_VERSION_CHECK(6, 7, 2))
|
# if (QT_VERSION == QT_VERSION_CHECK(6, 7, 2))
|
||||||
style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
|
style &= ~(WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
|
||||||
# endif
|
# endif
|
||||||
if (_fixSize) {
|
if (m_fixSize) {
|
||||||
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);;
|
::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_CAPTION);;
|
||||||
for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
|
for (int i = 0; i <= QGuiApplication::screens().count() - 1; ++i) {
|
||||||
connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
|
connect(QGuiApplication::screens().at(i), &QScreen::logicalDotsPerInchChanged, this, [=] {
|
||||||
@ -406,7 +429,7 @@ void Frameless::componentComplete() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const quint64 wid = reinterpret_cast<qint64>(hwnd);
|
const quint64 wid = reinterpret_cast<qint64>(hwnd);
|
||||||
if (wid != _current) {
|
if (wid != m_current) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto uMsg = msg->message;
|
const auto uMsg = msg->message;
|
||||||
@ -431,7 +454,7 @@ void Frameless::componentComplete() {
|
|||||||
*result = WVR_REDRAW;
|
*result = WVR_REDRAW;
|
||||||
return true;
|
return true;
|
||||||
} else if (uMsg == WM_NCHITTEST) {
|
} else if (uMsg == WM_NCHITTEST) {
|
||||||
if (_isWindows11OrGreater) {
|
if (m_isWindows11OrGreater) {
|
||||||
if (_hitMaximizeButton()) {
|
if (_hitMaximizeButton()) {
|
||||||
if (*result == HTNOWHERE) {
|
if (*result == HTNOWHERE) {
|
||||||
*result = HTZOOM;
|
*result = HTZOOM;
|
||||||
@ -450,12 +473,12 @@ void Frameless::componentComplete() {
|
|||||||
::GetClientRect(hwnd, &clientRect);
|
::GetClientRect(hwnd, &clientRect);
|
||||||
auto clientWidth = clientRect.right - clientRect.left;
|
auto clientWidth = clientRect.right - clientRect.left;
|
||||||
auto clientHeight = clientRect.bottom - clientRect.top;
|
auto clientHeight = clientRect.bottom - clientRect.top;
|
||||||
bool left = nativeLocalPos.x < _margins;
|
bool left = nativeLocalPos.x < m_margins;
|
||||||
bool right = nativeLocalPos.x > clientWidth - _margins;
|
bool right = nativeLocalPos.x > clientWidth - m_margins;
|
||||||
bool top = nativeLocalPos.y < _margins;
|
bool top = nativeLocalPos.y < m_margins;
|
||||||
bool bottom = nativeLocalPos.y > clientHeight - _margins;
|
bool bottom = nativeLocalPos.y > clientHeight - m_margins;
|
||||||
*result = 0;
|
*result = 0;
|
||||||
if (!_fixSize && !_isFullScreen() && !_isMaximized()) {
|
if (!m_fixSize && !_isFullScreen() && !_isMaximized()) {
|
||||||
if (left && top) {
|
if (left && top) {
|
||||||
*result = HTTOPLEFT;
|
*result = HTTOPLEFT;
|
||||||
} else if (left && bottom) {
|
} else if (left && bottom) {
|
||||||
@ -488,21 +511,21 @@ void Frameless::componentComplete() {
|
|||||||
return false;
|
return false;
|
||||||
} else if (uMsg == WM_NCACTIVATE) {
|
} else if (uMsg == WM_NCACTIVATE) {
|
||||||
*result = TRUE;
|
*result = TRUE;
|
||||||
if (effective() || (!effect().isEmpty() && _currentEffect!="normal")) {
|
if (effective() || (!effect().isEmpty() && m_currentEffect != "normal")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) {
|
} else if (m_isWindows11OrGreater && (uMsg == WM_NCLBUTTONDBLCLK || uMsg == WM_NCLBUTTONDOWN)) {
|
||||||
if (_hitMaximizeButton()) {
|
if (_hitMaximizeButton()) {
|
||||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
QMouseEvent event = QMouseEvent(QEvent::MouseButtonPress, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||||
QGuiApplication::sendEvent(_maximizeButton, &event);
|
QGuiApplication::sendEvent(m_maximizeButton, &event);
|
||||||
_setMaximizePressed(true);
|
_setMaximizePressed(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (_isWindows11OrGreater && (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP)) {
|
} else if (m_isWindows11OrGreater && (uMsg == WM_NCLBUTTONUP || uMsg == WM_NCRBUTTONUP)) {
|
||||||
if (_hitMaximizeButton()) {
|
if (_hitMaximizeButton()) {
|
||||||
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
QMouseEvent event = QMouseEvent(QEvent::MouseButtonRelease, QPoint(), QPoint(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
|
||||||
QGuiApplication::sendEvent(_maximizeButton, &event);
|
QGuiApplication::sendEvent(m_maximizeButton, &event);
|
||||||
_setMaximizePressed(false);
|
_setMaximizePressed(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -517,7 +540,7 @@ void Frameless::componentComplete() {
|
|||||||
const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0));
|
const bool spacePressed = ((wParam == VK_SPACE) || (::GetKeyState(VK_SPACE) < 0));
|
||||||
if (altPressed && spacePressed) {
|
if (altPressed && spacePressed) {
|
||||||
auto pos = window()->position();
|
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) {
|
} else if (uMsg == WM_SYSCOMMAND) {
|
||||||
if (wParam == SC_MINIMIZE) {
|
if (wParam == SC_MINIMIZE) {
|
||||||
@ -566,7 +589,7 @@ void Frameless::_showSystemMenu(QPoint point) {
|
|||||||
::EnableMenuItem(hMenu, SC_MOVE, MFS_ENABLED);
|
::EnableMenuItem(hMenu, SC_MOVE, MFS_ENABLED);
|
||||||
::EnableMenuItem(hMenu, SC_RESTORE, MFS_DISABLED);
|
::EnableMenuItem(hMenu, SC_RESTORE, MFS_DISABLED);
|
||||||
}
|
}
|
||||||
if (!_fixSize && !_isMaximized() && !_isFullScreen()) {
|
if (!m_fixSize && !_isMaximized() && !_isFullScreen()) {
|
||||||
::EnableMenuItem(hMenu, SC_SIZE, MFS_ENABLED);
|
::EnableMenuItem(hMenu, SC_SIZE, MFS_ENABLED);
|
||||||
::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_ENABLED);
|
::EnableMenuItem(hMenu, SC_MAXIMIZE, MFS_ENABLED);
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,12 +9,6 @@
|
|||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
||||||
#pragma comment (lib, "user32.lib")
|
|
||||||
#pragma comment (lib, "dwmapi.lib")
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <windowsx.h>
|
|
||||||
#include <dwmapi.h>
|
|
||||||
enum _DWM_SYSTEMBACKDROP_TYPE {
|
enum _DWM_SYSTEMBACKDROP_TYPE {
|
||||||
_DWMSBT_AUTO, // [Default] Let DWM automatically decide the system-drawn backdrop for this
|
_DWMSBT_AUTO, // [Default] Let DWM automatically decide the system-drawn backdrop for this
|
||||||
// window.
|
// window.
|
||||||
@ -76,26 +70,6 @@ enum ACCENT_FLAG {
|
|||||||
ACCENT_ENABLE_ACRYLIC_WITH_LUMINOSITY = 482
|
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
|
#endif
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
Loading…
Reference in New Issue
Block a user