A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
Glass menus: the glass no longer stays on screen by itself
Eternity070628d325477450b7
diff --git a/src/menu/context_menu.cpp b/src/menu/context_menu.cppindex 21a45b0..b8a93ae 100644--- a/src/menu/context_menu.cpp+++ b/src/menu/context_menu.cpp@@ -777,7 +777,12 @@ static bool AskShellGlass(const Level& L, bool dark) {}static void TellShellGlass(const Level& L, int code) {if (!L.ext) return;- if (HWND sh = FindWindowW(L"ShellMensagens", nullptr)) PostMessageW(sh, VidroMsgId(), (WPARAM)L.hwnd, VidroParam(L, code, false));+ HWND sh = FindWindowW(L"ShellMensagens", nullptr);+ if (!sh) return;+ // menu do próprio Shell (Dock, mesa): na hora, sem fila. Postado, o aviso só era lido depois da ação escolhida+ // (que roda nesta mesma thread), e o vidro ficava na tela sem o menu enquanto ela rodava.+ if (GetWindowThreadProcessId(sh, nullptr) == GetCurrentThreadId()) SendMessageW(sh, VidroMsgId(), (WPARAM)L.hwnd, VidroParam(L, code, false));+ else PostMessageW(sh, VidroMsgId(), (WPARAM)L.hwnd, VidroParam(L, code, false));}// Abre um nível. Raiz: no ponteiro. Submenu: ao lado do item pai (parentWin/itemTop em pixels de tela).diff --git a/src/shell/backdrop.cpp b/src/shell/backdrop.cppindex 12fc8ac..8147e6a 100644--- a/src/shell/backdrop.cpp+++ b/src/shell/backdrop.cpp@@ -41,6 +41,7 @@#include <atomic>#include <random>#include <map>+#include <chrono>#include <vector>#include <string>#include <algorithm>@@ -1538,6 +1539,20 @@ void backdrop::Fade(HWND h, float opacity, float scale, float cx, float cy) {e.root.Scale({ scale, scale, 1 });}+// some sozinho na Composição (o DWM anima): vale mesmo que esta thread fique ocupada (a ação escolhida no menu)+void backdrop::FadeOutAnim(HWND h, int ms) {+ auto it = g_entries.find(h);+ if (it == g_entries.end()) return;+ try {+ auto a = g_comp.CreateScalarKeyFrameAnimation();+ a.InsertKeyFrame(1.f, 0.f, g_comp.CreateCubicBezierEasingFunction({ 0.3f, 0.f }, { 0.6f, 1.f }));+ a.Duration(std::chrono::milliseconds(std::max(1, ms)));+ it->second.root.StartAnimation(L"Opacity", a);+ } catch (...) {+ it->second.root.Opacity(0);+ }+}+void backdrop::Set(HWND h, float w, float hgt, float radius, D2D1_COLOR_F tint) {auto it = g_entries.find(h);if (it == g_entries.end()) return;diff --git a/src/shell/menus.cpp b/src/shell/menus.cppindex b63a827..848be54 100644--- a/src/shell/menus.cpp+++ b/src/shell/menus.cpp@@ -801,13 +801,13 @@ void CALLBACK MvTick(HWND, UINT, UINT_PTR, DWORD) {HWND menu = it->first; MenuVidro& v = it->second;// o menu sumiu sem avisar (app fechou, travou): o vidro vai junto. Logo depois de abrir ele ainda não apareceu.bool gone = !IsWindow(menu) || (!IsWindowVisible(menu) && now - v.born > 600);- if (!gone && v.fadeT0) {- float p = (now - v.fadeT0) / (float)std::max(1, v.fadeMs);- if (p >= 1) gone = true;- else backdrop::Fade(v.back, 1 - p * p * (3 - 2 * p), 1, v.w / 2.f, v.h / 2.f); // acompanha o fade do menu- }- if (gone) { MvFree(v); it = g_mv.erase(it); }- else ++it;+ if (!gone && v.fadeT0 && now - v.fadeT0 > (DWORD)v.fadeMs + 40) gone = true; // o fade (da Composição) acabou+ if (gone) { MvFree(v); it = g_mv.erase(it); continue; }+ // sempre logo atrás do menu: se algo (o Dock subindo, outro "sempre por cima") passou entre os dois ou por cima+ // do vidro, o vidro cobria o texto e só ele ficava na tela+ if (!v.fadeT0 && GetWindow(menu, GW_HWNDNEXT) != v.back)+ SetWindowPos(v.back, menu, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);+ ++it;}if (g_mv.empty() && g_mvTimer) { KillTimer(nullptr, g_mvTimer); g_mvTimer = 0; }}@@ -826,10 +826,17 @@ bool menus::VidroMsg(UINT m, WPARAM w, LPARAM l, LRESULT* res) {auto it = g_mv.find(menu);if (code == 0) { if (it != g_mv.end()) { MvFree(it->second); g_mv.erase(it); } return true; }if (code == 2) {- if (it != g_mv.end() && !it->second.fadeT0) { it->second.fadeT0 = GetTickCount() | 1; it->second.fadeMs = (int)((p >> 28) & 0xFFF); }+ if (it != g_mv.end() && !it->second.fadeT0) {+ it->second.fadeT0 = GetTickCount() | 1;+ it->second.fadeMs = (int)((p >> 28) & 0xFFF);+ backdrop::FadeOutAnim(it->second.back, it->second.fadeMs); // junto com o fade do menu, também na Composição+ }return true;}if (code != 1 || !MenuGlassOn()) return true;+ // o menu pede antes de aparecer; já visível = o pedido chegou atrasado (o menu desistiu de esperar e ficou com o+ // vidro dele): sem vidro nosso, senão ele ficava sozinho na tela quando o menu sumisse+ if (IsWindowVisible(menu)) return true;if (it != g_mv.end()) { MvFree(it->second); g_mv.erase(it); }MenuVidro v;v.dark = (p & 4) != 0;diff --git a/src/shell/shell.h b/src/shell/shell.hindex a4ee2fd..4aad0ee 100644--- a/src/shell/shell.h+++ b/src/shell/shell.h@@ -556,6 +556,7 @@ void Detach(HWND h); // a janela vai ser destruída: solta o vidro delavoid Restart(); // refaz o vidro real do zero (Ajustes: "Reiniciar o Liquid Glass")void Set(HWND h, float w, float hgt, float radius, D2D1_COLOR_F tint); // pxvoid Fade(HWND h, float opacity, float scale, float cx, float cy); // animação: opacidade e escala em volta de (cx, cy) px+void FadeOutAnim(HWND h, int ms); // some em ms pela Composição (não depende desta thread)// Conteúdo desenhado DENTRO do vidro (mesma árvore da Composição): vidro e desenho chegam à tela no mesmo// quadro. Numa janela à parte (swap chain), a borda do vidro ficava um quadro atrás do desenho quando o// painel mudava de tamanho. Coordenadas em DIP (scale = DPI/96); o contexto é do dispositivo de ui::Gpu()