Minor tweaks

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2021-08-11 17:58:47 +08:00
parent c6e5545b4d
commit 5a2d498445
8 changed files with 72 additions and 37 deletions

View File

@ -94,8 +94,10 @@ if(NOT BUILD_SHARED_LIBS)
endif() endif()
if(MSVC) if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /utf-8) target_compile_options(${PROJECT_NAME} PRIVATE /utf-8 /permissive-)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(${PROJECT_NAME} PRIVATE /JMC)
else()
target_compile_options(${PROJECT_NAME} PRIVATE /guard:cf) target_compile_options(${PROJECT_NAME} PRIVATE /guard:cf)
target_link_options(${PROJECT_NAME} PRIVATE /GUARD:CF) target_link_options(${PROJECT_NAME} PRIVATE /GUARD:CF)
endif() endif()
@ -111,18 +113,24 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE
) )
if(TEST_UNIX) if(TEST_UNIX)
target_compile_definitions(${PROJECT_NAME} PRIVATE FRAMELESSHELPER_TEST_UNIX) target_compile_definitions(${PROJECT_NAME} PRIVATE
FRAMELESSHELPER_TEST_UNIX
)
endif() endif()
if(WIN32) if(WIN32)
set(NTDDI_WIN10_19H1 0x0A000007)
target_compile_definitions(${PROJECT_NAME} PRIVATE target_compile_definitions(${PROJECT_NAME} PRIVATE
WIN32_LEAN_AND_MEAN WIN32_LEAN_AND_MEAN
_CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS
UNICODE UNICODE
_UNICODE _UNICODE
WINVER=${NTDDI_WIN10_19H1}
_WIN32_WINNT=${NTDDI_WIN10_19H1}
) )
unset(NTDDI_WIN10_19H1)
target_link_libraries(${PROJECT_NAME} PRIVATE target_link_libraries(${PROJECT_NAME} PRIVATE
user32 shell32 gdi32 dwmapi dwmapi
) )
endif() endif()

View File

@ -15,7 +15,7 @@ win32 {
_UNICODE _UNICODE
CONFIG += windeployqt CONFIG += windeployqt
CONFIG -= embed_manifest_exe CONFIG -= embed_manifest_exe
LIBS += -luser32 -lshell32 -lgdi32 -ldwmapi LIBS += -ldwmapi
RC_FILE = $$PWD/windows.rc RC_FILE = $$PWD/windows.rc
OTHER_FILES += $$PWD/windows.manifest OTHER_FILES += $$PWD/windows.manifest
} }

View File

@ -37,13 +37,15 @@ target_compile_definitions(MainWindow PRIVATE
) )
if(MSVC) if(MSVC)
target_compile_options(MainWindow PRIVATE /utf-8) target_compile_options(MainWindow PRIVATE /utf-8 /permissive-)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(MainWindow PRIVATE /JMC)
else()
target_compile_options(MainWindow PRIVATE /guard:cf) target_compile_options(MainWindow PRIVATE /guard:cf)
target_link_options(MainWindow PRIVATE /GUARD:CF) target_link_options(MainWindow PRIVATE /GUARD:CF)
endif() endif()
endif() endif()
if(WIN32) if(WIN32)
target_link_libraries(MainWindow PRIVATE user32 shell32 gdi32 dwmapi) target_link_libraries(MainWindow PRIVATE dwmapi)
endif() endif()

View File

@ -35,13 +35,15 @@ target_compile_definitions(Quick PRIVATE
) )
if(MSVC) if(MSVC)
target_compile_options(Quick PRIVATE /utf-8) target_compile_options(Quick PRIVATE /utf-8 /permissive-)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(Quick PRIVATE /JMC)
else()
target_compile_options(Quick PRIVATE /guard:cf) target_compile_options(Quick PRIVATE /guard:cf)
target_link_options(Quick PRIVATE /GUARD:CF) target_link_options(Quick PRIVATE /GUARD:CF)
endif() endif()
endif() endif()
if(WIN32) if(WIN32)
target_link_libraries(Quick PRIVATE user32 shell32 gdi32 dwmapi) target_link_libraries(Quick PRIVATE dwmapi)
endif() endif()

View File

@ -35,13 +35,15 @@ target_compile_definitions(Widget PRIVATE
) )
if(MSVC) if(MSVC)
target_compile_options(Widget PRIVATE /utf-8) target_compile_options(Widget PRIVATE /utf-8 /permissive-)
if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(Widget PRIVATE /JMC)
else()
target_compile_options(Widget PRIVATE /guard:cf) target_compile_options(Widget PRIVATE /guard:cf)
target_link_options(Widget PRIVATE /GUARD:CF) target_link_options(Widget PRIVATE /GUARD:CF)
endif() endif()
endif() endif()
if(WIN32) if(WIN32)
target_link_libraries(Widget PRIVATE user32 shell32 gdi32 dwmapi) target_link_libraries(Widget PRIVATE dwmapi)
endif() endif()

View File

@ -114,11 +114,22 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event)
return Qt::Edges{}; return Qt::Edges{};
} (); } ();
const bool hitTestVisible = Utilities::isHitTestVisibleInChrome(window); const bool hitTestVisible = Utilities::isHitTestVisibleInChrome(window);
const bool isInTitlebarArea = (localMousePosition.y() > resizeBorderHeight) bool isInTitlebarArea = false;
&& (localMousePosition.y() <= (titleBarHeight + resizeBorderHeight)) if ((window->windowState() == Qt::WindowMaximized)
&& (localMousePosition.x() > resizeBorderWidth) || (window->windowState() == Qt::WindowFullScreen)) {
&& (localMousePosition.x() < (windowWidth - resizeBorderWidth)) isInTitlebarArea = (localMousePosition.y() >= 0)
&& !hitTestVisible; && (localMousePosition.y() <= titleBarHeight)
&& (localMousePosition.x() >= 0)
&& (localMousePosition.x() <= windowWidth)
&& !hitTestVisible;
}
if (window->windowState() == Qt::WindowNoState) {
isInTitlebarArea = (localMousePosition.y() > resizeBorderHeight)
&& (localMousePosition.y() <= (titleBarHeight + resizeBorderHeight))
&& (localMousePosition.x() > resizeBorderWidth)
&& (localMousePosition.x() < (windowWidth - resizeBorderWidth))
&& !hitTestVisible;
}
const auto mouseEvent = static_cast<QMouseEvent *>(event); const auto mouseEvent = static_cast<QMouseEvent *>(event);
if (type == QEvent::MouseButtonDblClick) { if (type == QEvent::MouseButtonDblClick) {
if (mouseEvent->button() != Qt::MouseButton::LeftButton) { if (mouseEvent->button() != Qt::MouseButton::LeftButton) {

View File

@ -33,27 +33,27 @@
#ifndef WM_NCUAHDRAWCAPTION #ifndef WM_NCUAHDRAWCAPTION
// Not documented, only available since Windows Vista // Not documented, only available since Windows Vista
#define WM_NCUAHDRAWCAPTION 0x00AE #define WM_NCUAHDRAWCAPTION (0x00AE)
#endif #endif
#ifndef WM_NCUAHDRAWFRAME #ifndef WM_NCUAHDRAWFRAME
// Not documented, only available since Windows Vista // Not documented, only available since Windows Vista
#define WM_NCUAHDRAWFRAME 0x00AF #define WM_NCUAHDRAWFRAME (0x00AF)
#endif #endif
#ifndef ABM_GETAUTOHIDEBAREX #ifndef ABM_GETAUTOHIDEBAREX
// Only available since Windows 8.1 // Only available since Windows 8.1
#define ABM_GETAUTOHIDEBAREX 0x0000000b #define ABM_GETAUTOHIDEBAREX (0x0000000b)
#endif #endif
#ifndef IsMinimized #ifndef IsMinimized
// Only available since Windows 2000 // Only available since Windows 2000
#define IsMinimized(window) IsIconic(window) #define IsMinimized(window) (IsIconic(window))
#endif #endif
#ifndef IsMaximized #ifndef IsMaximized
// Only available since Windows 2000 // Only available since Windows 2000
#define IsMaximized(window) IsZoomed(window) #define IsMaximized(window) (IsZoomed(window))
#endif #endif
#ifndef GET_X_LPARAM #ifndef GET_X_LPARAM
@ -315,13 +315,12 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// have the WS_POPUP size, so we don't have to worry about // have the WS_POPUP size, so we don't have to worry about
// borders, and the default frame will be fine. // borders, and the default frame will be fine.
if (IsMaximized(msg->hwnd) && (window->windowState() != Qt::WindowFullScreen)) { if (IsMaximized(msg->hwnd) && (window->windowState() != Qt::WindowFullScreen)) {
// Windows automatically adds a standard width border to all // When a window is maximized, its size is actually a little bit more
// sides when a window is maximized. We have to remove it // than the monitor's work area. The window is positioned and sized in
// otherwise the content of our window will be cut-off from // such a way that the resize handles are outside of the monitor and
// the screen. // then the window is clipped to the monitor so that the resize handle
// The value of border width and border height should be // do not appear because you don't need them (because you can't resize
// identical in most cases, when the scale factor is 1.0, it // a window when it's maximized unless you restore it).
// should be eight pixels.
const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true); const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true);
clientRect->top += rbh; clientRect->top += rbh;
if (!shouldHaveWindowFrame()) { if (!shouldHaveWindowFrame()) {
@ -338,7 +337,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Make sure to use MONITOR_DEFAULTTONEAREST, so that this will // Make sure to use MONITOR_DEFAULTTONEAREST, so that this will
// still find the right monitor even when we're restoring from // still find the right monitor even when we're restoring from
// minimized. // minimized.
if (IsMaximized(msg->hwnd)) { if (IsMaximized(msg->hwnd) || (window->windowState() == Qt::WindowFullScreen)) {
APPBARDATA abd; APPBARDATA abd;
SecureZeroMemory(&abd, sizeof(abd)); SecureZeroMemory(&abd, sizeof(abd));
abd.cbSize = sizeof(abd); abd.cbSize = sizeof(abd);
@ -573,9 +572,18 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const int rbw = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, true); const int rbw = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderWidth, true);
const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true); const int rbh = Utilities::getSystemMetric(window, SystemMetric::ResizeBorderHeight, true);
const int tbh = Utilities::getSystemMetric(window, SystemMetric::TitleBarHeight, true); const int tbh = Utilities::getSystemMetric(window, SystemMetric::TitleBarHeight, true);
const bool isTitleBar = (localMouse.y() > rbh) && (localMouse.y() <= (rbh + tbh)) bool isTitleBar = false;
&& (localMouse.x() > rbw) && (localMouse.x() < (ww - rbw)) if ((window->windowState() == Qt::WindowMaximized)
&& !Utilities::isHitTestVisibleInChrome(window); || (window->windowState() == Qt::WindowFullScreen)) {
isTitleBar = (localMouse.y() >= 0) && (localMouse.y() <= tbh)
&& (localMouse.x() >= 0) && (localMouse.x() <= ww)
&& !Utilities::isHitTestVisibleInChrome(window);
}
if (window->windowState() == Qt::WindowNoState) {
isTitleBar = (localMouse.y() > rbh) && (localMouse.y() <= (rbh + tbh))
&& (localMouse.x() > rbw) && (localMouse.x() < (ww - rbw))
&& !Utilities::isHitTestVisibleInChrome(window);
}
const bool isTop = localMouse.y() <= rbh; const bool isTop = localMouse.y() <= rbh;
if (shouldHaveWindowFrame()) { if (shouldHaveWindowFrame()) {
// This will handle the left, right and bottom parts of the frame // This will handle the left, right and bottom parts of the frame

View File

@ -30,11 +30,13 @@ win32 {
WIN32_LEAN_AND_MEAN \ WIN32_LEAN_AND_MEAN \
_CRT_SECURE_NO_WARNINGS \ _CRT_SECURE_NO_WARNINGS \
UNICODE \ UNICODE \
_UNICODE _UNICODE \
WINVER=0x0A000007 \
_WIN32_WINNT=0x0A000007
HEADERS += framelesshelper_win32.h HEADERS += framelesshelper_win32.h
SOURCES += \ SOURCES += \
utilities_win32.cpp \ utilities_win32.cpp \
framelesshelper_win32.cpp framelesshelper_win32.cpp
LIBS += -luser32 -lshell32 -lgdi32 -ldwmapi LIBS += -ldwmapi
RC_FILE = framelesshelper.rc RC_FILE = framelesshelper.rc
} }