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

Commit d71dc75

Browse files
committed
mica material: fix drawing on multi-monitor scenario
1 parent 43f632f commit d71dc75

File tree

17 files changed

+409
-220
lines changed

17 files changed

+409
-220
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ option(FRAMELESSHELPER_ENABLE_CFGUARD "Enable Control Flow Guard (CFG)." OFF)
5454
option(FRAMELESSHELPER_EXAMPLES_STANDALONE "Build the demo projects as standalone CMake projects." OFF)
5555
cmake_dependent_option(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD "macOS only: build universal library/example for Mac." ON APPLE OFF)
5656
option(FRAMELESSHELPER_FORCE_LTO "Force enable LTO/LTCG even when building static libraries." OFF)
57-
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." OFF)
57+
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON)
5858

5959
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui)
6060
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

examples/dialog/CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE
5757

5858
if(WIN32)
5959
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
60-
generate_win32_rc_file(
61-
PATH "${__rc_path}"
62-
VERSION "${PROJECT_VERSION}"
63-
COMPANY "wangwenx190"
64-
DESCRIPTION "FramelessHelper Demo Application: Dialog"
65-
COPYRIGHT "MIT License"
66-
PRODUCT "FramelessHelper Demo"
67-
ICONS "../shared/example.ico"
68-
)
60+
if(NOT EXISTS "${__rc_path}")
61+
generate_win32_rc_file(
62+
PATH "${__rc_path}"
63+
VERSION "${PROJECT_VERSION}"
64+
COMPANY "wangwenx190"
65+
DESCRIPTION "FramelessHelper Demo Application: Dialog"
66+
COPYRIGHT "MIT License"
67+
PRODUCT "FramelessHelper Demo"
68+
ICONS "../shared/example.ico"
69+
)
70+
endif()
6971
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
70-
generate_win32_manifest_file(
71-
PATH "${__manifest_path}"
72-
ID "org.wangwenx190.demo.Dialog"
73-
VERSION "${PROJECT_VERSION}"
74-
VISTA_COMPAT
75-
WIN7_COMPAT
76-
WIN8_COMPAT
77-
WIN8_1_COMPAT
78-
WIN10_COMPAT
79-
WIN11_COMPAT
80-
XAML_ISLANDS_COMPAT
81-
UTF8_CODEPAGE
82-
)
72+
if(NOT EXISTS "${__manifest_path}")
73+
generate_win32_manifest_file(
74+
PATH "${__manifest_path}"
75+
ID "org.wangwenx190.demo.Dialog"
76+
VERSION "${PROJECT_VERSION}"
77+
VISTA_COMPAT
78+
WIN7_COMPAT
79+
WIN8_COMPAT
80+
WIN8_1_COMPAT
81+
WIN10_COMPAT
82+
WIN11_COMPAT
83+
XAML_ISLANDS_COMPAT
84+
UTF8_CODEPAGE
85+
)
86+
endif()
8387
target_sources(${DEMO_NAME} PRIVATE
8488
"${__rc_path}"
8589
"${__manifest_path}"

examples/mainwindow/CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,33 @@ target_sources(${DEMO_NAME} PRIVATE
6262

6363
if(WIN32)
6464
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
65-
generate_win32_rc_file(
66-
PATH "${__rc_path}"
67-
VERSION "${PROJECT_VERSION}"
68-
COMPANY "wangwenx190"
69-
DESCRIPTION "FramelessHelper Demo Application: MainWindow"
70-
COPYRIGHT "MIT License"
71-
PRODUCT "FramelessHelper Demo"
72-
ICONS "../shared/example.ico"
73-
)
65+
if(NOT EXISTS "${__rc_path}")
66+
generate_win32_rc_file(
67+
PATH "${__rc_path}"
68+
VERSION "${PROJECT_VERSION}"
69+
COMPANY "wangwenx190"
70+
DESCRIPTION "FramelessHelper Demo Application: MainWindow"
71+
COPYRIGHT "MIT License"
72+
PRODUCT "FramelessHelper Demo"
73+
ICONS "../shared/example.ico"
74+
)
75+
endif()
7476
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
75-
generate_win32_manifest_file(
76-
PATH "${__manifest_path}"
77-
ID "org.wangwenx190.demo.MainWindow"
78-
VERSION "${PROJECT_VERSION}"
79-
VISTA_COMPAT
80-
WIN7_COMPAT
81-
WIN8_COMPAT
82-
WIN8_1_COMPAT
83-
WIN10_COMPAT
84-
WIN11_COMPAT
85-
XAML_ISLANDS_COMPAT
86-
UTF8_CODEPAGE
87-
)
77+
if(NOT EXISTS "${__manifest_path}")
78+
generate_win32_manifest_file(
79+
PATH "${__manifest_path}"
80+
ID "org.wangwenx190.demo.MainWindow"
81+
VERSION "${PROJECT_VERSION}"
82+
VISTA_COMPAT
83+
WIN7_COMPAT
84+
WIN8_COMPAT
85+
WIN8_1_COMPAT
86+
WIN10_COMPAT
87+
WIN11_COMPAT
88+
XAML_ISLANDS_COMPAT
89+
UTF8_CODEPAGE
90+
)
91+
endif()
8892
target_sources(${DEMO_NAME} PRIVATE
8993
"${__rc_path}"
9094
"${__manifest_path}"

examples/openglwidget/CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -65,29 +65,33 @@ target_sources(${DEMO_NAME} PRIVATE
6565

6666
if(WIN32)
6767
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
68-
generate_win32_rc_file(
69-
PATH "${__rc_path}"
70-
VERSION "${PROJECT_VERSION}"
71-
COMPANY "wangwenx190"
72-
DESCRIPTION "FramelessHelper Demo Application: OpenGLWidget"
73-
COPYRIGHT "MIT License"
74-
PRODUCT "FramelessHelper Demo"
75-
ICONS "../shared/example.ico"
76-
)
68+
if(NOT EXISTS "${__rc_path}")
69+
generate_win32_rc_file(
70+
PATH "${__rc_path}"
71+
VERSION "${PROJECT_VERSION}"
72+
COMPANY "wangwenx190"
73+
DESCRIPTION "FramelessHelper Demo Application: OpenGLWidget"
74+
COPYRIGHT "MIT License"
75+
PRODUCT "FramelessHelper Demo"
76+
ICONS "../shared/example.ico"
77+
)
78+
endif()
7779
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
78-
generate_win32_manifest_file(
79-
PATH "${__manifest_path}"
80-
ID "org.wangwenx190.demo.OpenGLWidget"
81-
VERSION "${PROJECT_VERSION}"
82-
VISTA_COMPAT
83-
WIN7_COMPAT
84-
WIN8_COMPAT
85-
WIN8_1_COMPAT
86-
WIN10_COMPAT
87-
WIN11_COMPAT
88-
XAML_ISLANDS_COMPAT
89-
UTF8_CODEPAGE
90-
)
80+
if(NOT EXISTS "${__manifest_path}")
81+
generate_win32_manifest_file(
82+
PATH "${__manifest_path}"
83+
ID "org.wangwenx190.demo.OpenGLWidget"
84+
VERSION "${PROJECT_VERSION}"
85+
VISTA_COMPAT
86+
WIN7_COMPAT
87+
WIN8_COMPAT
88+
WIN8_1_COMPAT
89+
WIN10_COMPAT
90+
WIN11_COMPAT
91+
XAML_ISLANDS_COMPAT
92+
UTF8_CODEPAGE
93+
)
94+
endif()
9195
target_sources(${DEMO_NAME} PRIVATE
9296
"${__rc_path}"
9397
"${__manifest_path}"

examples/quick/CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE
5757

5858
if(WIN32)
5959
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
60-
generate_win32_rc_file(
61-
PATH "${__rc_path}"
62-
VERSION "${PROJECT_VERSION}"
63-
COMPANY "wangwenx190"
64-
DESCRIPTION "FramelessHelper Demo Application: Quick"
65-
COPYRIGHT "MIT License"
66-
PRODUCT "FramelessHelper Demo"
67-
ICONS "../shared/example.ico"
68-
)
60+
if(NOT EXISTS "${__rc_path}")
61+
generate_win32_rc_file(
62+
PATH "${__rc_path}"
63+
VERSION "${PROJECT_VERSION}"
64+
COMPANY "wangwenx190"
65+
DESCRIPTION "FramelessHelper Demo Application: Quick"
66+
COPYRIGHT "MIT License"
67+
PRODUCT "FramelessHelper Demo"
68+
ICONS "../shared/example.ico"
69+
)
70+
endif()
6971
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
70-
generate_win32_manifest_file(
71-
PATH "${__manifest_path}"
72-
ID "org.wangwenx190.demo.Quick"
73-
VERSION "${PROJECT_VERSION}"
74-
VISTA_COMPAT
75-
WIN7_COMPAT
76-
WIN8_COMPAT
77-
WIN8_1_COMPAT
78-
WIN10_COMPAT
79-
WIN11_COMPAT
80-
XAML_ISLANDS_COMPAT
81-
UTF8_CODEPAGE
82-
)
72+
if(NOT EXISTS "${__manifest_path}")
73+
generate_win32_manifest_file(
74+
PATH "${__manifest_path}"
75+
ID "org.wangwenx190.demo.Quick"
76+
VERSION "${PROJECT_VERSION}"
77+
VISTA_COMPAT
78+
WIN7_COMPAT
79+
WIN8_COMPAT
80+
WIN8_1_COMPAT
81+
WIN10_COMPAT
82+
WIN11_COMPAT
83+
XAML_ISLANDS_COMPAT
84+
UTF8_CODEPAGE
85+
)
86+
endif()
8387
target_sources(${DEMO_NAME} PRIVATE
8488
"${__rc_path}"
8589
"${__manifest_path}"

examples/widget/CMakeLists.txt

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE
5757

5858
if(WIN32)
5959
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
60-
generate_win32_rc_file(
61-
PATH "${__rc_path}"
62-
VERSION "${PROJECT_VERSION}"
63-
COMPANY "wangwenx190"
64-
DESCRIPTION "FramelessHelper Demo Application: Widget"
65-
COPYRIGHT "MIT License"
66-
PRODUCT "FramelessHelper Demo"
67-
ICONS "../shared/example.ico"
68-
)
60+
if(NOT EXISTS "${__rc_path}")
61+
generate_win32_rc_file(
62+
PATH "${__rc_path}"
63+
VERSION "${PROJECT_VERSION}"
64+
COMPANY "wangwenx190"
65+
DESCRIPTION "FramelessHelper Demo Application: Widget"
66+
COPYRIGHT "MIT License"
67+
PRODUCT "FramelessHelper Demo"
68+
ICONS "../shared/example.ico"
69+
)
70+
endif()
6971
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
70-
generate_win32_manifest_file(
71-
PATH "${__manifest_path}"
72-
ID "org.wangwenx190.demo.Widget"
73-
VERSION "${PROJECT_VERSION}"
74-
VISTA_COMPAT
75-
WIN7_COMPAT
76-
WIN8_COMPAT
77-
WIN8_1_COMPAT
78-
WIN10_COMPAT
79-
WIN11_COMPAT
80-
XAML_ISLANDS_COMPAT
81-
UTF8_CODEPAGE
82-
)
72+
if(NOT EXISTS "${__manifest_path}")
73+
generate_win32_manifest_file(
74+
PATH "${__manifest_path}"
75+
ID "org.wangwenx190.demo.Widget"
76+
VERSION "${PROJECT_VERSION}"
77+
VISTA_COMPAT
78+
WIN7_COMPAT
79+
WIN8_COMPAT
80+
WIN8_1_COMPAT
81+
WIN10_COMPAT
82+
WIN11_COMPAT
83+
XAML_ISLANDS_COMPAT
84+
UTF8_CODEPAGE
85+
)
86+
endif()
8387
target_sources(${DEMO_NAME} PRIVATE
8488
"${__rc_path}"
8589
"${__manifest_path}"

include/FramelessHelper/Core/micamaterial.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#pragma once
2626

2727
#include <FramelessHelper/Core/framelesshelpercore_global.h>
28+
#include <QtCore/qrect.h>
2829

2930
FRAMELESSHELPER_BEGIN_NAMESPACE
3031

@@ -62,7 +63,13 @@ class FRAMELESSHELPER_CORE_API MicaMaterial : public QObject
6263
void setFallbackEnabled(const bool value);
6364

6465
public Q_SLOTS:
65-
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true);
66+
void paint(QPainter *painter, const QRect &rect, const bool active = true);
67+
68+
[[deprecated("Use another overload instead.")]]
69+
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true)
70+
{
71+
paint(painter, QRect{ pos, size }, active);
72+
}
6673

6774
Q_SIGNALS:
6875
void tintColorChanged();

include/FramelessHelper/Core/private/framelesshelpercore_global_p.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,21 @@ FRAMELESSHELPER_CORE_API void registerInitializeHook(const InitializeHookCallbac
103103
FRAMELESSHELPER_CORE_API void registerUninitializeHook(const UninitializeHookCallback &cb);
104104

105105
FRAMELESSHELPER_END_NAMESPACE
106+
107+
#define DECLARE_SIZE_COMPARE_OPERATORS(Type1, Type2) \
108+
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator>(const Type1 &lhs, const Type2 &rhs) noexcept \
109+
{ \
110+
return ((lhs.width() * lhs.height()) > (rhs.width() * rhs.height())); \
111+
} \
112+
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator>=(const Type1 &lhs, const Type2 &rhs) noexcept \
113+
{ \
114+
return (operator>(lhs, rhs) || operator==(lhs, rhs)); \
115+
} \
116+
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator<(const Type1 &lhs, const Type2 &rhs) noexcept \
117+
{ \
118+
return (operator!=(lhs, rhs) && !operator>(lhs, rhs)); \
119+
} \
120+
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator<=(const Type1 &lhs, const Type2 &rhs) noexcept \
121+
{ \
122+
return (operator<(lhs, rhs) || operator==(lhs, rhs)); \
123+
}

include/FramelessHelper/Core/private/micamaterial_p.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,18 @@ class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject
5252

5353
Q_NODISCARD static QColor systemFallbackColor();
5454

55+
Q_NODISCARD static QSize monitorSize();
56+
Q_NODISCARD static QSize wallpaperSize();
57+
58+
Q_NODISCARD QPoint mapToWallpaper(const QPoint &pos) const;
59+
Q_NODISCARD QSize mapToWallpaper(const QSize &size) const;
60+
Q_NODISCARD QRect mapToWallpaper(const QRect &rect) const;
61+
5562
public Q_SLOTS:
5663
void maybeGenerateBlurredWallpaper(const bool force = false);
5764
void updateMaterialBrush();
58-
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true);
65+
void paint(QPainter *painter, const QRect &rect, const bool active = true);
66+
void forceRebuildWallpaper();
5967

6068
private:
6169
void initialize();

include/FramelessHelper/Core/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ FRAMELESSHELPER_CORE_API void registerThemeChangeNotification();
8181
[[nodiscard]] FRAMELESSHELPER_CORE_API QPoint fromNativeGlobalPosition(const QWindow *window, const QPoint &point);
8282
[[nodiscard]] FRAMELESSHELPER_CORE_API int horizontalAdvance(const QFontMetrics &fm, const QString &str);
8383
[[nodiscard]] FRAMELESSHELPER_CORE_API qreal getRelativeScaleFactor(const quint32 oldDpi, const quint32 newDpi);
84+
[[nodiscard]] FRAMELESSHELPER_CORE_API QSizeF rescaleSize(const QSizeF &oldSize, const quint32 oldDpi, const quint32 newDpi);
8485
[[nodiscard]] FRAMELESSHELPER_CORE_API QSize rescaleSize(const QSize &oldSize, const quint32 oldDpi, const quint32 newDpi);
86+
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isValidGeometry(const QRectF &rect);
8587
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isValidGeometry(const QRect &rect);
8688
[[nodiscard]] FRAMELESSHELPER_CORE_API QColor getAccentColor();
8789
[[nodiscard]] FRAMELESSHELPER_CORE_API quint32 defaultScreenDpi();

0 commit comments

Comments
 (0)