From c229915e9d4b2818155f3650869726fdcbe7e21d Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 摹曛, 21 12月 2023 14:12:26 +0800
Subject: [PATCH] Prepare to add mica

---
 src/core/contexts/cocoawindowcontext.mm  |    5 -----
 src/core/windowagentbase.h               |    2 +-
 README.md                                |   13 +++++++++++++
 src/core/contexts/win32windowcontext.cpp |   27 ++++++++++++++++++++++++++-
 4 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/README.md b/README.md
index ae739dd..f5bad1d 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,19 @@
 
 Support as many system native features as possible without requiring additional dependencies.
 
+<!-- ## Why using QWindowKit?
+
+Here're why `QWindowKit` is better than `FramelessHelper`:
+
++ Full support of Windows 11 Snap Layout
++ Most of the redundant codes and architectural flaws are eliminated, and the binary size compiled by MSVC is about 1/9 of `FramelessHelper`
++ A critical issue that moving window forces the entire window to be repainted on Windows is fixed
++ Capable to cope with WinId mutation, and `QWebEngineView` is perfectly supported
++ Simpler APIs, more detailed documentation and comments
++ A lot of bugs are fixed
+
+Feature requests are welcome. -->
+
 ## Supported Platforms
 
 + Microsoft Windows
diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm
index 69ed562..d438001 100644
--- a/src/core/contexts/cocoawindowcontext.mm
+++ b/src/core/contexts/cocoawindowcontext.mm
@@ -371,11 +371,6 @@
 
     void CocoaWindowContext::virtual_hook(int id, void *data) {
         switch (id) {
-            case ShowSystemMenuHook: {
-                // TODO: mac system menu
-                return;
-            }
-
             case SystemButtonAreaChangedHook: {
                 // TODO: mac system button rect updated
                 return;
diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 418a211..1b969cf 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -914,13 +914,38 @@
                 const auto &oldVar = *static_cast<const QVariant *>(args[2]);
 
                 if (key == QStringLiteral("no-frame-shadow")) {
+                    if (!windowId)
+                        return;
                     if (newVar.toBool()) {
                         // TODO: set off
                     } else {
                         // TODO: set on
                     }
-                }
+                } else if (key == QStringLiteral("mica-material")) {
+                    if (!windowId || !isWin11OrGreater())
+                        return;
+                    const auto hwnd = reinterpret_cast<HWND>(windowId);
+                    if (newVar.toBool()) {
+                        /*
 
+                        // We need to extend the window frame into the whole client area to be able
+                        // to see the blurred window background.
+                        static constexpr const MARGINS margins = {-1, -1, -1, -1};
+                        ::DwmExtendFrameIntoClientArea(hwnd, &margins);
+
+                        // Use official DWM API to enable Mica/Mica Alt, available since Windows 11
+                        // (10.0.22000).
+                        const DWM_SYSTEMBACKDROP_TYPE blurType =
+                            DWMSBT_MAINWINDOW; // This one is Mica, if you want to enable Mica Alt,
+                                               // use DWMSBT_TABBEDWINDOW instead.
+                        DynamicApis::instance().pDwmSetWindowAttribute(
+                            hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &blurType, sizeof(blurType));
+
+                        */
+                    } else {
+                        // TODO: set off
+                    }
+                }
                 return;
             }
 
diff --git a/src/core/windowagentbase.h b/src/core/windowagentbase.h
index d5b02fa..6ac3dc3 100644
--- a/src/core/windowagentbase.h
+++ b/src/core/windowagentbase.h
@@ -32,7 +32,7 @@
         void setWindowAttribute(const QString &key, const QVariant &var);
 
     public Q_SLOTS:
-        void showSystemMenu(const QPoint &pos);
+        void showSystemMenu(const QPoint &pos); // Only available on Windows now
         void centralize();
         void raise();
 

--
Gitblit v1.9.1