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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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