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

Commit

Permalink
win: add more safe guards to dpi hacks
Browse files Browse the repository at this point in the history
And some other minor improvements.

Signed-off-by: Yuhang Zhao <[email protected]>
  • Loading branch information
wangwenx190 committed Nov 11, 2022
1 parent ddb2dcc commit 0277804
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 92 deletions.
32 changes: 21 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
cmake_minimum_required(VERSION 3.20)

project(FramelessHelper
VERSION 2.3.2.0
VERSION 2.3.3.0
DESCRIPTION "Cross-platform window customization framework for Qt Widgets and Qt Quick."
HOMEPAGE_URL "https://github.com/wangwenx190/framelesshelper/"
LANGUAGES CXX
Expand Down Expand Up @@ -88,13 +88,21 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(PROJECT_VERSION_COMMIT "UNKNOWN")
find_program(GIT_EXECUTABLE_PATH git)
if(GIT_EXECUTABLE_PATH AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE_PATH} rev-parse HEAD
OUTPUT_VARIABLE PROJECT_VERSION_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
# Get a git hash value. We do not want to use git command here
# because we don't want to make git a build-time dependency.
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/HEAD")
file(READ "${CMAKE_SOURCE_DIR}/.git/HEAD" PROJECT_VERSION_COMMIT)
string(STRIP "${PROJECT_VERSION_COMMIT}" PROJECT_VERSION_COMMIT)
if(PROJECT_VERSION_COMMIT MATCHES "^ref: (.*)")
set(HEAD "${CMAKE_MATCH_1}")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git/${HEAD}")
file(READ "${CMAKE_SOURCE_DIR}/.git/${HEAD}" PROJECT_VERSION_COMMIT)
string(STRIP "${PROJECT_VERSION_COMMIT}" PROJECT_VERSION_COMMIT)
else()
file(READ "${CMAKE_SOURCE_DIR}/.git/packed-refs" PACKED_REFS)
string(REGEX REPLACE ".*\n([0-9a-f]+) ${HEAD}\n.*" "\\1" PROJECT_VERSION_COMMIT "\n${PACKED_REFS}")
endif()
endif()
endif()

set(PROJECT_COMPILE_DATETIME "UNKNOWN")
Expand Down Expand Up @@ -136,8 +144,10 @@ message("#######################################")
message("CMake version: ${CMAKE_VERSION}")
message("Host system: ${CMAKE_HOST_SYSTEM}")
message("Host processor: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
#message("C compiler: ${CMAKE_C_COMPILER}") # Currently we are not using any C compilers.
message("C++ compiler: ${CMAKE_CXX_COMPILER}")
#message("C compiler: ${CMAKE_C_COMPILER_ID} (${CMAKE_C_COMPILER})") # Currently we are not using any C compilers.
#message("C compiler version: ${CMAKE_C_COMPILER_VERSION}")
message("C++ compiler: ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER})")
message("C++ compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
message("Linker: ${CMAKE_LINKER}")
message("Make program: ${CMAKE_MAKE_PROGRAM}")
message("Build type: ${CMAKE_BUILD_TYPE}")
Expand All @@ -158,7 +168,7 @@ message("Qt version: ${QT_VERSION}")
message("#######################################")
message("FramelessHelper version: ${PROJECT_VERSION}")
message("FramelessHelper commit hash: ${PROJECT_VERSION_COMMIT}")
message("FramelessHelper configure date and time: ${PROJECT_COMPILE_DATETIME}")
message("FramelessHelper configure date and time: ${PROJECT_COMPILE_DATETIME} (UTC)")
message("Build the static version of FramelessHelper: ${FRAMELESSHELPER_BUILD_STATIC}")
message("Build the FramelessHelper::Widgets module: ${FRAMELESSHELPER_BUILD_WIDGETS}")
message("Build the FramelessHelper::Quick module: ${FRAMELESSHELPER_BUILD_QUICK}")
Expand Down
4 changes: 2 additions & 2 deletions qmake/inc/core/framelesshelper.version
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

[[maybe_unused]] inline constexpr const int FRAMELESSHELPER_VERSION_MAJOR = 2;
[[maybe_unused]] inline constexpr const int FRAMELESSHELPER_VERSION_MINOR = 3;
[[maybe_unused]] inline constexpr const int FRAMELESSHELPER_VERSION_PATCH = 2;
[[maybe_unused]] inline constexpr const int FRAMELESSHELPER_VERSION_PATCH = 3;
[[maybe_unused]] inline constexpr const int FRAMELESSHELPER_VERSION_TWEAK = 0;
[[maybe_unused]] inline constexpr const char FRAMELESSHELPER_VERSION_STR[] = "2.3.2.0\0";
[[maybe_unused]] inline constexpr const char FRAMELESSHELPER_VERSION_STR[] = "2.3.3.0\0";
[[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMMIT_STR[] = "UNKNOWN\0";
[[maybe_unused]] inline constexpr const char FRAMELESSHELPER_COMPILE_DATETIME_STR[] = "UNKNOWN\0";

Expand Down
5 changes: 5 additions & 0 deletions src/core/framelesshelpercore_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,19 @@ void setApplicationOSThemeAware()
set = true;

#ifdef Q_OS_WINDOWS
// This hack is needed to let AllowDarkModeForWindow() work.
Utils::setDarkModeAllowedForApp(true);
# if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
// Qt gained the ability to detect system theme change since 5.15 but
// it's not quite useful until Qt6.
Utils::setQtDarkModeAwareEnabled(true);
# endif
#endif

#if ((defined(Q_OS_LINUX) && (QT_VERSION < QT_VERSION_CHECK(6, 4, 0))) || \
(defined(Q_OS_MACOS) && (QT_VERSION < QT_VERSION_CHECK(5, 12, 0))))
// Linux: Qt 6.4 gained the ability to detect system theme change.
// macOS: Qt 5.12.
Utils::registerThemeChangeNotification();
#endif
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/framelessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,16 @@ void FramelessManagerPrivate::addWindow(const SystemParameters &params)
g_helper()->mutex.lock();
g_helper()->data[windowId].screenChangeConnection =
connect(window, &QWindow::screenChanged, window, [windowId, window](QScreen *screen){
Q_UNUSED(screen);
// Force a WM_NCCALCSIZE event to inform Windows about our custom window frame,
// this is only necessary when the window is being moved cross monitors.
Utils::triggerFrameChange(windowId);
// For some reason the window is not repainted correctly when moving cross monitors,
// we workaround this issue by force a re-paint and re-layout of the window by triggering
// a resize event manually. Although the actual size does not change, the issue we
// observed disappeared indeed, amazingly.
window->resize(window->size());
});
Q_UNUSED(screen);
// Force a WM_NCCALCSIZE event to inform Windows about our custom window frame,
// this is only necessary when the window is being moved cross monitors.
Utils::triggerFrameChange(windowId);
// For some reason the window is not repainted correctly when moving cross monitors,
// we workaround this issue by force a re-paint and re-layout of the window by triggering
// a resize event manually. Although the actual size does not change, the issue we
// observed disappeared indeed, amazingly.
window->resize(window->size());
});
g_helper()->mutex.unlock();
}
}
Expand Down
Loading

0 comments on commit 0277804

Please sign in to comment.