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

Commit

Permalink
mica material: fix drawing on multi-monitor scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Jul 15, 2023
1 parent 43f632f commit d71dc75
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ option(FRAMELESSHELPER_ENABLE_CFGUARD "Enable Control Flow Guard (CFG)." OFF)
option(FRAMELESSHELPER_EXAMPLES_STANDALONE "Build the demo projects as standalone CMake projects." OFF)
cmake_dependent_option(FRAMELESSHELPER_ENABLE_UNIVERSAL_BUILD "macOS only: build universal library/example for Mac." ON APPLE OFF)
option(FRAMELESSHELPER_FORCE_LTO "Force enable LTO/LTCG even when building static libraries." OFF)
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." OFF)
option(FRAMELESSHELPER_REPRODUCIBLE_OUTPUT "Don't update the build commit and date dynamically." ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
Expand Down
48 changes: 26 additions & 22 deletions examples/dialog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE

if(WIN32)
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Dialog"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
if(NOT EXISTS "${__rc_path}")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Dialog"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
endif()
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Dialog"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
if(NOT EXISTS "${__manifest_path}")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Dialog"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
endif()
target_sources(${DEMO_NAME} PRIVATE
"${__rc_path}"
"${__manifest_path}"
Expand Down
48 changes: 26 additions & 22 deletions examples/mainwindow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,33 @@ target_sources(${DEMO_NAME} PRIVATE

if(WIN32)
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: MainWindow"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
if(NOT EXISTS "${__rc_path}")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: MainWindow"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
endif()
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.MainWindow"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
if(NOT EXISTS "${__manifest_path}")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.MainWindow"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
endif()
target_sources(${DEMO_NAME} PRIVATE
"${__rc_path}"
"${__manifest_path}"
Expand Down
48 changes: 26 additions & 22 deletions examples/openglwidget/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,29 +65,33 @@ target_sources(${DEMO_NAME} PRIVATE

if(WIN32)
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: OpenGLWidget"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
if(NOT EXISTS "${__rc_path}")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: OpenGLWidget"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
endif()
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.OpenGLWidget"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
if(NOT EXISTS "${__manifest_path}")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.OpenGLWidget"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
endif()
target_sources(${DEMO_NAME} PRIVATE
"${__rc_path}"
"${__manifest_path}"
Expand Down
48 changes: 26 additions & 22 deletions examples/quick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE

if(WIN32)
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Quick"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
if(NOT EXISTS "${__rc_path}")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Quick"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
endif()
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Quick"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
if(NOT EXISTS "${__manifest_path}")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Quick"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
endif()
target_sources(${DEMO_NAME} PRIVATE
"${__rc_path}"
"${__manifest_path}"
Expand Down
48 changes: 26 additions & 22 deletions examples/widget/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,33 @@ target_sources(${DEMO_NAME} PRIVATE

if(WIN32)
set(__rc_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.rc")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Widget"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
if(NOT EXISTS "${__rc_path}")
generate_win32_rc_file(
PATH "${__rc_path}"
VERSION "${PROJECT_VERSION}"
COMPANY "wangwenx190"
DESCRIPTION "FramelessHelper Demo Application: Widget"
COPYRIGHT "MIT License"
PRODUCT "FramelessHelper Demo"
ICONS "../shared/example.ico"
)
endif()
set(__manifest_path "${PROJECT_BINARY_DIR}/${DEMO_NAME}.manifest")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Widget"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
if(NOT EXISTS "${__manifest_path}")
generate_win32_manifest_file(
PATH "${__manifest_path}"
ID "org.wangwenx190.demo.Widget"
VERSION "${PROJECT_VERSION}"
VISTA_COMPAT
WIN7_COMPAT
WIN8_COMPAT
WIN8_1_COMPAT
WIN10_COMPAT
WIN11_COMPAT
XAML_ISLANDS_COMPAT
UTF8_CODEPAGE
)
endif()
target_sources(${DEMO_NAME} PRIVATE
"${__rc_path}"
"${__manifest_path}"
Expand Down
9 changes: 8 additions & 1 deletion include/FramelessHelper/Core/micamaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#pragma once

#include <FramelessHelper/Core/framelesshelpercore_global.h>
#include <QtCore/qrect.h>

FRAMELESSHELPER_BEGIN_NAMESPACE

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

public Q_SLOTS:
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true);
void paint(QPainter *painter, const QRect &rect, const bool active = true);

[[deprecated("Use another overload instead.")]]
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true)
{
paint(painter, QRect{ pos, size }, active);
}

Q_SIGNALS:
void tintColorChanged();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,21 @@ FRAMELESSHELPER_CORE_API void registerInitializeHook(const InitializeHookCallbac
FRAMELESSHELPER_CORE_API void registerUninitializeHook(const UninitializeHookCallback &cb);

FRAMELESSHELPER_END_NAMESPACE

#define DECLARE_SIZE_COMPARE_OPERATORS(Type1, Type2) \
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator>(const Type1 &lhs, const Type2 &rhs) noexcept \
{ \
return ((lhs.width() * lhs.height()) > (rhs.width() * rhs.height())); \
} \
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator>=(const Type1 &lhs, const Type2 &rhs) noexcept \
{ \
return (operator>(lhs, rhs) || operator==(lhs, rhs)); \
} \
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator<(const Type1 &lhs, const Type2 &rhs) noexcept \
{ \
return (operator!=(lhs, rhs) && !operator>(lhs, rhs)); \
} \
[[maybe_unused]] [[nodiscard]] static inline constexpr bool operator<=(const Type1 &lhs, const Type2 &rhs) noexcept \
{ \
return (operator<(lhs, rhs) || operator==(lhs, rhs)); \
}
10 changes: 9 additions & 1 deletion include/FramelessHelper/Core/private/micamaterial_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ class FRAMELESSHELPER_CORE_API MicaMaterialPrivate : public QObject

Q_NODISCARD static QColor systemFallbackColor();

Q_NODISCARD static QSize monitorSize();
Q_NODISCARD static QSize wallpaperSize();

Q_NODISCARD QPoint mapToWallpaper(const QPoint &pos) const;
Q_NODISCARD QSize mapToWallpaper(const QSize &size) const;
Q_NODISCARD QRect mapToWallpaper(const QRect &rect) const;

public Q_SLOTS:
void maybeGenerateBlurredWallpaper(const bool force = false);
void updateMaterialBrush();
void paint(QPainter *painter, const QSize &size, const QPoint &pos, const bool active = true);
void paint(QPainter *painter, const QRect &rect, const bool active = true);
void forceRebuildWallpaper();

private:
void initialize();
Expand Down
2 changes: 2 additions & 0 deletions include/FramelessHelper/Core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ FRAMELESSHELPER_CORE_API void registerThemeChangeNotification();
[[nodiscard]] FRAMELESSHELPER_CORE_API QPoint fromNativeGlobalPosition(const QWindow *window, const QPoint &point);
[[nodiscard]] FRAMELESSHELPER_CORE_API int horizontalAdvance(const QFontMetrics &fm, const QString &str);
[[nodiscard]] FRAMELESSHELPER_CORE_API qreal getRelativeScaleFactor(const quint32 oldDpi, const quint32 newDpi);
[[nodiscard]] FRAMELESSHELPER_CORE_API QSizeF rescaleSize(const QSizeF &oldSize, const quint32 oldDpi, const quint32 newDpi);
[[nodiscard]] FRAMELESSHELPER_CORE_API QSize rescaleSize(const QSize &oldSize, const quint32 oldDpi, const quint32 newDpi);
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isValidGeometry(const QRectF &rect);
[[nodiscard]] FRAMELESSHELPER_CORE_API bool isValidGeometry(const QRect &rect);
[[nodiscard]] FRAMELESSHELPER_CORE_API QColor getAccentColor();
[[nodiscard]] FRAMELESSHELPER_CORE_API quint32 defaultScreenDpi();
Expand Down
2 changes: 1 addition & 1 deletion include/FramelessHelper/Quick/private/quickimageitem_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FRAMELESSHELPER_QUICK_API QuickImageItemPrivate : public QObject
void fromImage(const QImage &value, QPainter *painter) const;
void fromPixmap(const QPixmap &value, QPainter *painter) const;
void fromIcon(const QIcon &value, QPainter *painter) const;
Q_NODISCARD QRect paintArea() const;
Q_NODISCARD QRectF paintArea() const;

private:
QuickImageItem *q_ptr = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Q_SLOTS:
void rebindWindow();
void forceRegenerateWallpaperImageCache();
void appendNode(WallpaperImageNode *node);
void removeNode(WallpaperImageNode *node);
void updateFallbackColor();

private:
Expand Down
Loading

0 comments on commit d71dc75

Please sign in to comment.