A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
Tray icons survive Shell restarts; Notification Center stack clicks
Eternity0706288ac84de93e0d
diff --git a/src/shell/notificacoes.cpp b/src/shell/notificacoes.cppindex 60c127f..a4ab66f 100644--- a/src/shell/notificacoes.cpp+++ b/src/shell/notificacoes.cpp@@ -1085,8 +1085,10 @@ const Hit* HitAt(D2D1_POINT_2F p) {}DWORD g_expandedAt = 0; // quando uma pilha foi aberta+DWORD g_clickAt = 0; // último clique dentro da Central: o foco que some logo depois não fecha (abrir a pilha)void Click(D2D1_POINT_2F p) {+ g_clickAt = GetTickCount();const Hit* h = HitAt(p);if (!h) { Close(); return; } // clique no vazio da coluna: fecha, como clicar foraHit hit = *h;@@ -1108,7 +1110,7 @@ void Click(D2D1_POINT_2F p) {}switch (hit.act) {case A_STACK:- if (hit.group >= 0 && hit.group < (int)g_groups.size()) { g_expanded.insert(g_groups[hit.group].aumid); g_expandedAt = GetTickCount(); }+ if (hit.group >= 0 && hit.group < (int)g_groups.size()) { g_expanded.insert(g_groups[hit.group].aumid); g_expandedAt = GetTickCount(); Log(L"notificações: abriu a pilha de %ls", g_groups[hit.group].app.c_str()); }break;case A_CARD:// segundo clique de um clique duplo na pilha: só abre o grupo (não abre o app nem fecha a central)@@ -1178,7 +1180,7 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {if (!g_open || g_menu) return 0;HWND f = GetForegroundWindow(); DWORD pid = 0;if (f) GetWindowThreadProcessId(f, &pid);- if (f && pid != GetCurrentProcessId()) { Log(L"notificações: fechou (outro programa na frente)"); Close(); }+ if (f && pid != GetCurrentProcessId() && GetTickCount() - g_clickAt >= 800) { Log(L"notificações: fechou (outro programa na frente)"); Close(); }else SetForegroundWindow(g_wnd); // ninguém (ou o próprio Shell) na frente: continua aberta}return 0;@@ -1207,6 +1209,7 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {return 0;}if (!to) { SetTimer(h, T_FOCO, 150, nullptr); return 0; } // "para ninguém" (ao abrir uma pilha): confere já já+ if (GetTickCount() - g_clickAt < 800) { SetTimer(h, T_FOCO, 150, nullptr); return 0; } // logo depois de um clique aqui dentro: não foi clique forawchar_t cls[64] = {}; if (to) GetClassNameW(to, cls, 64);Log(L"notificações: fechou (perdeu o foco para %ls)", cls);Close();diff --git a/src/shell/tray.cpp b/src/shell/tray.cppindex 2d9b2b4..3a801ab 100644--- a/src/shell/tray.cpp+++ b/src/shell/tray.cpp@@ -1,7 +1,9 @@// Bandeja: Shell_TrayWnd próprio acima do do Explorador (protótipo em src/tools/bandeja_teste.cpp,// estudo em docs/estudo-bandeja.md). Recebe Shell_NotifyIcon dos apps e repassa tudo ao Explorador.#include "shell.h"-#include <shellapi.h>+#include <shellapi.h>+#include <shlwapi.h>+#pragma comment(lib, "shlwapi.lib")#include <algorithm>#pragma pack(push, 4)@@ -121,6 +123,31 @@ bool tray::DoExplorer(COPYDATASTRUCT* cd, LRESULT* res) {return true;}+// Outra Shell_TrayWnd de um WacOSShell (o Shell antigo, num reinício, ainda fechando): o aviso "TaskbarCreated"+// espera ela sumir. Antes ele ia na hora, os apps mandavam os ícones para a bandeja do Shell antigo, que logo fechava+// levando os ícones junto (a bandeja ficava vazia depois de reiniciar o Shell)+static bool g_avisoPendente;+static DWORD g_avisoDesde;+static bool OutroShellComBandeja() {+ HWND h = nullptr;+ while ((h = FindWindowExW(nullptr, h, L"Shell_TrayWnd", nullptr))) {+ if (h == g_tray) continue;+ DWORD pid = 0; GetWindowThreadProcessId(h, &pid);+ if (!pid || pid == GetCurrentProcessId()) continue;+ if (HANDLE ph = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid)) {+ wchar_t p[MAX_PATH] = {}; DWORD n = MAX_PATH;+ bool shell = QueryFullProcessImageNameW(ph, 0, p, &n) && StrStrIW(p, L"WacOSShell") != nullptr;+ CloseHandle(ph);+ if (shell) return true;+ }+ }+ return false;+}+static void AvisarApps() {+ g_avisoPendente = false;+ SendNotifyMessageW(HWND_BROADCAST, RegisterWindowMessageW(L"TaskbarCreated"), 0, 0); // os apps mandam os ícones de novo+}+void tray::Start(std::function<void()> changed) {g_changed = changed;if (shell::nativo) {@@ -141,7 +168,8 @@ void tray::Start(std::function<void()> changed) {tb.left, tb.top, tb.right - tb.left, tb.bottom - tb.top, nullptr, nullptr, shell::inst, nullptr);g_notify = CreateWindowExW(0, L"TrayNotifyWnd", nullptr, WS_CHILD, 0, 0, 1, 1, g_tray, nullptr, shell::inst, nullptr);apps::ours.push_back(g_tray);- SendNotifyMessageW(HWND_BROADCAST, RegisterWindowMessageW(L"TaskbarCreated"), 0, 0);+ if (OutroShellComBandeja()) { g_avisoPendente = true; g_avisoDesde = GetTickCount(); Log(L"bandeja: esperando o Shell antigo fechar para chamar os ícones"); }+ else AvisarApps();Log(L"bandeja: Shell_TrayWnd próprio criado");}@@ -159,6 +187,11 @@ void tray::Stop() {}void tray::Keepalive() {+ if (g_avisoPendente && (!OutroShellComBandeja() || GetTickCount() - g_avisoDesde > 15000)) { // no máximo 15 s+ Log(L"bandeja: Shell antigo fechou, chamando os ícones");+ if (g_tray) SetWindowPos(g_tray, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);+ AvisarApps();+ }if (g_tray && FindWindowW(L"Shell_TrayWnd", nullptr) != g_tray)SetWindowPos(g_tray, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);}