Skip to content

armgit / WacOS

Public Imported from GitHub
0

A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.

Rust

Shell stalls (issue #32), Dock click-to-hide and Settings scrolling (issue #29)

Eternity0706280bfc0b281420
diff --git a/docs/registro-mudancas.txt b/docs/registro-mudancas.txt
index 7bf60c4..824f590 100644
--- a/docs/registro-mudancas.txt
+++ b/docs/registro-mudancas.txt
@@ -1231,3 +1231,19 @@ Compilado (tudo), instalado, Shell e reserva do Finder reiniciados às 23:07 sem
- src/shell/mesa.cpp: mesa::Papel, a imagem da nossa mesa ou, com o Explorador de fundo (o padrão, sem a nossa mesa), o papel de parede do Windows montado numa thread.
- Teste: mensagem ShellVidroMesaPreta (w=1 finge a mesa preta, só na memória). No Dock: normal RGB 47,48,69; mesa fingida preta 45,45,64; nenhum pixel escuro. NÃO reproduzido no PC do usuário da issue.
DESFAZER: reverter o commit.
+
+[2026-11-22 20:55, hora do PC] Issue #32 ("o Shell inteiro congela") e comentário da #29 (Dock, piscadas, rolagem).
+ Paradas da thread da interface do Shell achadas com pilha (amostra.exe, paradas de 400 ms ou mais, Shell instalado deste PC, 19:52-20:18):
+ - 10,2 s: dock BuildItems -> SHQueryRecycleBinW (Lixeira de todos os discos) a cada mudança no Dock. src/shell/dock.cpp: numa thread (PedirLixeira), uma por vez; o resultado volta por shell::NaInterface.
+ - 21,5 s e 15,1 s: missioncontrol::Warm -> LoadPng do papel de parede. src/shell/missioncontrol.cpp: lido e decodificado numa thread; a interface só desenha (medido: 118-160 ms na thread, 12-15 ms desenhando).
+ - 17,6 s (o vigia reiniciou o Shell): ctxmenu::WarmupAsync -> D3D11CreateDevice/CreateDevice do D2D; o driver da NVIDIA (nvspcap64, captura do ShadowPlay) grava em disco ao criar o dispositivo. src/menu/context_menu.cpp: dispositivo do vidro do menu criado numa thread; o compositor continua na janela.
+ - 10,2 s, 7,5 s, 3,2 s: ShellExecute na interface (abrir app pelo Dock, o Ajustes pela Ilha). Novo shell::Abrir (main.cpp, ShellExecuteEx numa thread STA); 45 chamadas trocadas em 16 arquivos. apps::Launch inteiro (versão nova do .exe, manifesto, atalho, ativador) numa thread com uma cópia do app.
+ - 8,0 s: apps::Refresh (tique de 1 s) -> ExeName -> GetFileVersionInfo de app recém-aberto. O nome bonito chega por uma thread; até lá, o nome do arquivo.
+ - 2,9 s: janelas::Start -> CreateProcess + WaitForInputIdle do hospedeiro de 32 bits: numa thread, e as janelas de 32 bits já abertas são revistas quando ele fica pronto (src/titulos/main.cpp ganhou o mesmo NaInterface).
+ - 2,9 s: Ilha, 1º desenho da Estante -> DirectWrite abrindo o arquivo da fonte de ícones. src/shell/ui.cpp: fontes da barra, dos ícones e do SF Pro carregadas numa thread ao iniciar (984 ms fora da interface).
+ - Sentinela (src/shell/sentinela.cpp): interface parada 1 s ou mais grava no shell.log a mensagem, a classe da janela e a pilha em módulo+deslocamento (o WacOSShell.exe se resolve com o WacOSShell.pdb da mesma build; guardar o PDB de cada release).
+ Dock (#29, "clicar no ícone não minimiza"): reproduzido com uma janela de teste (tdock.exe, cliques postados no ícone). Ocultar funcionava, mas a janela minimizada continuava sendo a da frente. src/shell/apps.cpp: Hide minimiza com ShowWindowAsync e passa a frente para a janela de cima de outro app; Activate sem esperas em janelas de outros programas. src/shell/dock.cpp: "app na frente" também pela janela dona e por outra janela do mesmo app; o log diz por que um clique ativou em vez de ocultar. Mensagem de teste ShellDockTesteIcone (w = janela; devolve o meio do ícone).
+ Rolagem dos Ajustes (#29): o passo vinha do SetTimer (~15,6 ms), 67-74 quadros/s numa tela de 180 Hz, com o desenho em ~5 ms. src/ajustes/main.cpp: passo a cada quadro do compositor (DwmFlush numa thread): 180-183 quadros/s, desenho 5,3 ms. A linha "rolagem" do ajustes-app.log agora separa conteúdo, cena desfocada, lateral, EndDraw e Present (src/finder/gfx.cpp: gfx::End mede; src/monitor/main.cpp só a declaração).
+ Piscadas (#29): NÃO reproduzidas. pisca.exe (Duplicação de Área de Trabalho, todo quadro, grade 32x16) com uma janela própria movendo e mudando de tamanho e o mouse postado no Dock: ~10 mil quadros, nenhuma piscada do Shell (as marcações eram o movimento da janela de teste e a etiqueta do Dock reagindo ao mouse falso).
+ Instalado (hash conferido): WacOSShell.exe, WacOSSettings.exe, WacOSTitleBars.exe. Um passo errado no meio: o WacOSTitleBars.exe do bin principal foi copiado uma vez antes do certo (sobrescrito em seguida pelo deste ramo).
+ DESFAZER: reverter os commits deste ramo e reinstalar os três exes de antes.
diff --git a/src/ajustes/main.cpp b/src/ajustes/main.cpp
index 2113e62..137aea9 100644
--- a/src/ajustes/main.cpp
+++ b/src/ajustes/main.cpp
@@ -11,6 +11,7 @@
#include <wincodec.h>
#include <set>
#include <thread>
+#include <atomic>
#include <condition_variable>
#include <mutex>
#include <cstdarg>
@@ -130,7 +131,10 @@ std::map<std::wstring, std::wstring> g_settings;
void Invalidate() { if (g_hwnd) InvalidateRect(g_hwnd, nullptr, FALSE); }
double Qpf() { static LARGE_INTEGER f{}; if (!f.QuadPart) QueryPerformanceFrequency(&f); return (double)f.QuadPart; }
// medida da rolagem (log "rolagem: ..."): quadros, tempo e quanto custa desenhar um quadro
-struct Rolagem { bool on = false; int n = 0; double soma = 0, pior = 0; LARGE_INTEGER ini{}, ult{}; } g_rol;
+struct Rolagem { bool on = false; int n = 0; double soma = 0, pior = 0, parte[6]{}; LARGE_INTEGER ini{}, ult{}; } g_rol;
+// partes do quadro (diagnóstico da rolagem, issue #29): 0 conteúdo, 1 cena desfocada, 2 barra lateral e resto, 3 EndDraw, 4 Present
+static LARGE_INTEGER g_marca;
+static void Marca(int k) { LARGE_INTEGER t; QueryPerformanceCounter(&t); if (g_rol.on && k >= 0) g_rol.parte[k] += (t.QuadPart - g_marca.QuadPart) * 1000.0 / Qpf(); g_marca = t; }
D2D1_POINT_2F ToDip(int x, int y) { return { x / g_scale, y / g_scale }; }
bool In(const D2D1_RECT_F& r, D2D1_POINT_2F p) { return p.x >= r.left && p.x < r.right && p.y >= r.top && p.y < r.bottom; }
D2D1_SIZE_F ClientDip() { RECT rc; GetClientRect(g_hwnd, &rc); return { rc.right / g_scale, rc.bottom / g_scale }; }
@@ -1688,6 +1692,7 @@ void Render() {
float x0 = SIDE_W + (Golden() ? 21.f : PAD), x1 = s.width - (Golden() ? 20.5f : PAD), w = x1 - x0;
// Tahoe: o conteúdo rola por baixo de Voltar/Avançar e do título (borda de rolagem desfocada), sem faixa opaca
ID2D1DeviceContext* mainDc = dc;
+ Marca(-1);
ID2D1DeviceContext* cdc = g_tahoe ? tahoe::SceneBegin(mainDc, 0, s, g_dpi) : nullptr;
if (cdc) { dc = cdc; c.dc = cdc; }
const float clipTop = cdc ? 0.f : TOOL_H;
@@ -1744,10 +1749,12 @@ void Render() {
}
g_contentH = y + g_scroll + 20 - TOOL_H;
dc->PopAxisAlignedClip();
+ Marca(0);
if (cdc) {
tahoe::SceneEnd(0);
dc = mainDc; c.dc = mainDc;
tahoe::SceneDraw(dc, 0, D2D1::RectF(SIDE_W + 0.5f, 0, s.width, s.height), TOOL_H + 10, D2D1::ColorF(pal.content.r, pal.content.g, pal.content.b, 0.9f));
+ Marca(1);
} else {
// barra de ferramentas: setas e título; linha embaixo quando há rolagem
br->SetColor(pal.content);
@@ -1778,7 +1785,9 @@ void Render() {
if (g_sheet.open) { g_hits.clear(); DrawSheet(c, pal); }
if (winClip) { dc->PopLayer(); tahoe::WindowRim(dc, br, s, winR, g_dark); }
br->Release();
- gfx::End();
+ Marca(2);
+ gfx::End(g_rol.on ? &g_rol.parte[3] : nullptr);
+ Marca(-1);
if (!g_toggleAnim.empty()) SetTimer(g_hwnd, T_ANIM, 15, nullptr);
}
@@ -1971,7 +1980,37 @@ void Click(D2D1_POINT_2F p, bool right) {
float MaxScroll() { return std::max(0.f, g_contentH - (ClientDip().height - TOOL_H)); }
float SideMaxScroll() { return std::max(0.f, g_sideH - (ClientDip().height - ACCOUNT_Y)); }
+// Rolagem no ritmo da tela (issue #29: "rolar engasga, principalmente nos Ajustes"). O passo vinha do SetTimer, que
+// o Windows só entrega a cada ~15,6 ms: 64 passos por segundo fora do compasso da tela (60, 120, 144 Hz), e a rolagem
+// dava trancos (medido: 67-74 quadros/s com o desenho em ~5 ms). Agora uma thread espera cada quadro do compositor
+// (DwmFlush) e pede um passo; o passo desenha na hora. Ela para quando a rolagem chega ao destino.
+const UINT WM_QUADRO = WM_APP + 77;
+std::atomic<bool> g_relogio{ false }, g_quadroPendente{ false };
+void LigaRelogio(HWND h) {
+ if (g_relogio.exchange(true)) return;
+ std::thread([h] {
+ while (g_relogio) {
+ DwmFlush();
+ if (!g_relogio || !IsWindow(h)) break;
+ if (!g_quadroPendente.exchange(true)) PostMessageW(h, WM_QUADRO, 0, 0);
+ }
+ g_relogio = false;
+ }).detach();
+}
+
LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
+ if (m == WM_QUADRO) {
+ g_quadroPendente = false;
+ if (!g_relogio) return 0;
+ WndProc(h, WM_TIMER, T_ANIM, 0); // o mesmo passo do temporizador
+ if (GetUpdateRect(h, nullptr, FALSE)) { // desenha já, neste quadro
+ LARGE_INTEGER a, b; QueryPerformanceCounter(&a);
+ Render(); ValidateRect(h, nullptr);
+ QueryPerformanceCounter(&b);
+ if (g_rol.on) { double ms = (b.QuadPart - a.QuadPart) * 1000.0 / Qpf(); g_rol.n++; g_rol.soma += ms; g_rol.pior = std::max(g_rol.pior, ms); }
+ }
+ return 0;
+ }
switch (m) {
case WM_INITMENUPOPUP: case WM_DRAWITEM: case WM_MEASUREITEM: case WM_MENUCHAR: {
LRESULT r = 0;
@@ -2055,7 +2094,7 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
else {
g_scrollTarget = std::clamp(g_scrollTarget + d, 0.f, MaxScroll());
if (!g_rol.on) { g_rol = {}; g_rol.on = true; QueryPerformanceCounter(&g_rol.ini); g_rol.ult = g_rol.ini; }
- SetTimer(h, T_ANIM, 4, nullptr);
+ LigaRelogio(h);
}
Invalidate();
return 0;
@@ -2086,10 +2125,13 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
if (std::fabs(diff) < 0.5f) g_scroll = g_scrollTarget; else g_scroll += diff * (float)(1.0 - std::pow(0.7, std::clamp(dt, 1.0, 60.0) / 15.0));
if (g_scroll == g_scrollTarget && g_rol.on) {
double tot = (now.QuadPart - g_rol.ini.QuadPart) * 1000.0 / Qpf();
- Log(L"rolagem: %d quadros em %.0f ms (%.0f quadros/s; desenho médio %.2f ms, pior %.2f ms)", g_rol.n, tot,
- tot > 0 ? g_rol.n * 1000.0 / tot : 0.0, g_rol.n ? g_rol.soma / g_rol.n : 0.0, g_rol.pior);
+ double q = g_rol.n ? g_rol.n : 1;
+ Log(L"rolagem: %d quadros em %.0f ms (%.0f quadros/s; desenho médio %.2f ms, pior %.2f ms; por quadro: conteúdo %.2f, cena desfocada %.2f, lateral %.2f, EndDraw %.2f, Present %.2f)", g_rol.n, tot,
+ tot > 0 ? g_rol.n * 1000.0 / tot : 0.0, g_rol.n ? g_rol.soma / g_rol.n : 0.0, g_rol.pior,
+ g_rol.parte[0] / q, g_rol.parte[1] / q, g_rol.parte[2] / q, g_rol.parte[3] / q, g_rol.parte[4] / q);
g_rol.on = false;
}
+ if (g_scroll == g_scrollTarget) g_relogio = false; // chegou: a thread do ritmo para
if (g_scroll == g_scrollTarget && g_toggleAnim.empty()) KillTimer(h, T_ANIM);
Invalidate();
} else if (w == T_CARET) {
diff --git a/src/finder/finder.h b/src/finder/finder.h
index fe9b5c5..16de9da 100644
--- a/src/finder/finder.h
+++ b/src/finder/finder.h
@@ -28,7 +28,7 @@ extern IDWriteFactory* dw;
bool Init(HWND hwnd);
void Resize(UINT w, UINT h);
ID2D1DeviceContext* Begin(float dpi); // já com BeginDraw; desenhe em DIPs
-void End(); // EndDraw + Present
+void End(double* ms = nullptr); // EndDraw + Present (ms: soma o tempo de cada um em ms[0] e ms[1])
ID2D1Bitmap* CreateBitmapBGRA(UINT w, UINT h, const void* pixels, UINT stride); // pré-multiplicado
IUnknown* Device(); // ID3D11Device
ID2D1Bitmap* BitmapFromTexture(IUnknown* texture); // ID3D11Texture2D BGRA -> bitmap (sem cópia)
diff --git a/src/finder/gfx.cpp b/src/finder/gfx.cpp
index f7c630e..3a2ed44 100644
--- a/src/finder/gfx.cpp
+++ b/src/finder/gfx.cpp
@@ -95,10 +95,14 @@ ID2D1DeviceContext* gfx::Begin(float dpi) {
return dc;
}
-void gfx::End() {
+void gfx::End(double* ms) {
+ LARGE_INTEGER f, a, b, c; QueryPerformanceFrequency(&f); QueryPerformanceCounter(&a);
HRESULT hr = dc->EndDraw();
+ QueryPerformanceCounter(&b);
if (FAILED(hr)) Log(L"erro: EndDraw 0x%08X", (unsigned)hr);
swap->Present(1, 0);
+ QueryPerformanceCounter(&c);
+ if (ms) { ms[0] += (b.QuadPart - a.QuadPart) * 1000.0 / f.QuadPart; ms[1] += (c.QuadPart - b.QuadPart) * 1000.0 / f.QuadPart; }
}
ID2D1Bitmap* gfx::CreateBitmapBGRA(UINT w, UINT h, const void* pixels, UINT stride) {
diff --git a/src/menu/context_menu.cpp b/src/menu/context_menu.cpp
index 2f5d2e6..9fe5a5a 100644
--- a/src/menu/context_menu.cpp
+++ b/src/menu/context_menu.cpp
@@ -25,6 +25,7 @@
#include <DispatcherQueue.h>
#include <chrono>
#include <thread>
+#include <atomic>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Numerics.h>
#include <winrt/Windows.System.h>
@@ -580,6 +581,28 @@ static bool g_wcTried, g_wcOk;
const float CARD_R_TAHOE = 12; // raio do canto do menu (DIP)
#define CARD_R (Golden() ? 11.f : CARD_R_TAHOE) // macOS 27: 11 (medido)
+// Dispositivos D3D/D2D do vidro do menu criados numa thread (o aquecimento do Shell): o D3D11CreateDevice passa pelo
+// driver, e o da NVIDIA (captura do ShadowPlay) grava em disco ao criar; com o disco ocupado a interface do Shell
+// parou 17,6 s aqui e o vigia reiniciou o Shell (pilhas de 22/11/2026 20:01, issue #32). O compositor continua na
+// thread da janela (CompReady); só o dispositivo vem pronto.
+static std::atomic<int> g_preEstado{ 0 }; // 0 nada, 1 criando, 2 pronto, 3 falhou
+static ID2D1Device* g_preD2d;
+static void PreparaDispositivo() {
+ if (g_preEstado.exchange(1)) return;
+ std::thread([] {
+ ID3D11Device* d3d = nullptr; IDXGIDevice* dx = nullptr; ID2D1Factory1* f1 = nullptr; ID2D1Device* d2 = nullptr;
+ if (SUCCEEDED(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &d3d, nullptr, nullptr)) &&
+ SUCCEEDED(d3d->QueryInterface(IID_PPV_ARGS(&dx))) &&
+ SUCCEEDED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory1), nullptr, (void**)&f1)))
+ f1->CreateDevice(dx, &d2);
+ if (f1) f1->Release();
+ if (dx) dx->Release();
+ if (d3d) d3d->Release();
+ g_preD2d = d2;
+ g_preEstado = d2 ? 2 : 3;
+ }).detach();
+}
+
static bool CompReady() {
if (g_wcTried) return g_wcOk;
g_wcTried = true;
@@ -589,6 +612,8 @@ static bool CompReady() {
winrt::check_hresult(CreateDispatcherQueueController(o, reinterpret_cast<ABI::Windows::System::IDispatcherQueueController**>(winrt::put_abi(g_wdq))));
}
g_wc = wuc::Compositor();
+ if (g_preEstado == 2 && g_preD2d) { g_wd2d = g_preD2d; g_preD2d = nullptr; } // veio pronto da thread
+ else {
ID3D11Device* d3d = nullptr;
winrt::check_hresult(D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr, 0, D3D11_SDK_VERSION, &d3d, nullptr, nullptr));
IDXGIDevice* dx = nullptr; d3d->QueryInterface(IID_PPV_ARGS(&dx));
@@ -596,6 +621,7 @@ static bool CompReady() {
winrt::check_hresult(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory1), nullptr, (void**)&f1));
winrt::check_hresult(f1->CreateDevice(dx, &g_wd2d));
dx->Release(); d3d->Release(); f1->Release();
+ }
auto ci = g_wc.as<ABI::Windows::UI::Composition::ICompositorInterop>();
winrt::check_hresult(ci->CreateGraphicsDevice(g_wd2d, reinterpret_cast<ABI::Windows::UI::Composition::ICompositionGraphicsDevice**>(winrt::put_abi(g_wgfx))));
g_wcOk = true;
@@ -1453,12 +1479,20 @@ void ctxmenu::Warmup(HWND owner, const std::wstring& folder, const std::wstring&
// O mesmo, numa thread própria: as extensões (DLLs) ficam carregadas no processo sem travar a janela por
// ~0,4-0,9 s; o primeiro botão direito depois disso já sai em ~70 ms.
+static void CALLBACK TerminaVidro(HWND, UINT, UINT_PTR id, DWORD) {
+ if (g_preEstado == 1) return; // a thread ainda está criando o dispositivo
+ KillTimer(nullptr, id);
+ if (g_wcTried) return; // um menu já abriu e montou tudo
+ LARGE_INTEGER f, a, b; QueryPerformanceFrequency(&f); QueryPerformanceCounter(&a);
+ bool ok = CompReady();
+ QueryPerformanceCounter(&b);
+ Log(L"vidro do menu pronto em %d ms na interface (%ls)", (int)((b.QuadPart - a.QuadPart) * 1000 / f.QuadPart), ok ? L"ok" : L"sem composição");
+}
+
void ctxmenu::WarmupAsync(const std::wstring& folder, const std::wstring& file) {
- if (Tahoe()) { // vidro do menu (D3D, D2D, composição): criado aqui, na thread da janela, e não no 1º menu
- LARGE_INTEGER f, a, b; QueryPerformanceFrequency(&f); QueryPerformanceCounter(&a);
- bool ok = CompReady();
- QueryPerformanceCounter(&b);
- Log(L"vidro do menu pronto em %d ms (%ls)", (int)((b.QuadPart - a.QuadPart) * 1000 / f.QuadPart), ok ? L"ok" : L"sem composição");
+ if (Tahoe() && !g_wcTried) { // vidro do menu (D3D, D2D, composição) antes do 1º menu: o dispositivo numa thread, o resto aqui
+ PreparaDispositivo();
+ SetTimer(nullptr, 0, 100, TerminaVidro);
}
std::thread([folder, file] {
if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) return;
diff --git a/src/monitor/main.cpp b/src/monitor/main.cpp
index bfe0ba9..a655690 100644
--- a/src/monitor/main.cpp
+++ b/src/monitor/main.cpp
@@ -48,7 +48,7 @@
// Peças do Finder (src/finder): desenho com alfa real (Direct2D sobre DirectComposition), a janela do
// Tahoe com cantos de 26 pt e vidro da Composição, e a sombra própria que segue o canto redondo. As mesmas
// que o Ajustes do Sistema usa. Declaradas aqui (o finder.h traz o Finder inteiro).
-namespace gfx { bool Init(HWND hwnd); void Resize(UINT w, UINT h); ID2D1DeviceContext* Begin(float dpi); void End(); }
+namespace gfx { bool Init(HWND hwnd); void Resize(UINT w, UINT h); ID2D1DeviceContext* Begin(float dpi); void End(double* ms = nullptr); }
namespace shadow { void Create(HWND main); void SetActive(bool active); void Update(); void Destroy(); void SetRadius(float dip); }
namespace tahoe {
float WindowR(); // 26 pt no Tahoe, 16 pt no Golden Gate
diff --git a/src/shell/apps.cpp b/src/shell/apps.cpp
index ce6ee48..1340960 100644
--- a/src/shell/apps.cpp
+++ b/src/shell/apps.cpp
@@ -403,15 +403,26 @@ bool apps::Refresh() {
x.id = id;
x.exe = exeOf[id];
x.wins = found[id];
- if (id.rfind(L"aumid:", 0) == 0) {
- std::wstring aumid = AumidOfWindow(x.wins[0].hwnd);
- x.launch = L"shell:AppsFolder\\" + aumid;
- x.name = DisplayNameOf(x.launch);
- if (x.name.empty()) x.name = ExeName(x.exe);
- } else {
- x.launch = ExeOfWindow(x.wins[0].hwnd);
- x.name = ExeName(x.launch);
+ // o nome bonito (descrição do .exe, nome do pacote) vem de uma thread: o GetFileVersionInfo carrega o .exe do
+ // disco e segurou a interface 8 s neste tique de 1 s (pilha de 22/11/2026 19:59, issue #32). Até chegar, o do arquivo.
+ bool pacote = id.rfind(L"aumid:", 0) == 0;
+ if (pacote) x.launch = L"shell:AppsFolder\\" + AumidOfWindow(x.wins[0].hwnd);
+ else x.launch = ExeOfWindow(x.wins[0].hwnd);
+ {
+ std::wstring arq = OurName(pacote ? x.exe : x.launch);
+ if (arq.empty()) { arq = (pacote ? x.exe : x.launch); arq = arq.substr(arq.find_last_of(L'\\') + 1); if (arq.size() > 4) arq.resize(arq.size() - 4); }
+ x.name = arq;
}
+ std::thread([id, pacote, launch = x.launch, exe = x.exe, provisorio = x.name] {
+ HRESULT ci = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ std::wstring n = pacote ? DisplayNameOf(launch) : ExeName(launch);
+ if (n.empty()) n = ExeName(exe);
+ if (SUCCEEDED(ci)) CoUninitialize();
+ if (n.empty() || n == provisorio) return;
+ shell::NaInterface([id, n, provisorio] {
+ for (auto& a : apps::list) if (a.id == id && a.name == provisorio) { a.name = n; dock::Update(); break; }
+ });
+ }).detach();
list.push_back(x);
Log(L"dock: aberto %ls (%ls)", x.name.c_str(), x.id.c_str());
}
@@ -979,30 +990,46 @@ static bool Heal(App& a) {
return true;
}
+// Abrir um app mexe com o disco (versão nova do .exe, manifesto do pacote, atalho .lnk, Electron ou não) e com o
+// ativador: tudo numa thread com uma cópia do app (issue #32: na thread da interface cada passo podia esperar o disco).
+static void LaunchNow(App a, const std::wstring& args);
void apps::Launch(App& a, const std::wstring& args) {
a.launchedAt = GetTickCount();
- if (a.pinned && Heal(a)) Save();
+ AllowSetForegroundWindow(ASFW_ANY); // o app aberto pela thread vem para a frente
+ std::thread([c = a, args] {
+ HRESULT ci = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ LaunchNow(c, args);
+ if (SUCCEEDED(ci)) CoUninitialize();
+ }).detach();
+}
+static void LaunchNow(App a, const std::wstring& args) {
+ if (a.pinned) {
+ std::wstring id0 = a.id;
+ if (Heal(a)) shell::NaInterface([id0, id = a.id, exe = a.exe, launch = a.launch] {
+ for (auto& x : apps::list) if (x.id == id0) { x.id = id; x.exe = exe; x.launch = launch; apps::Save(); break; }
+ });
+ }
for (const std::wstring* c : { &a.launch, &a.exe }) {
std::wstring aumid = PackagedAumid(*c);
if (aumid.empty()) continue;
std::wstring target = L"shell:AppsFolder\\" + aumid;
// Spotify e outros feitos sobre o Chromium: abertos sem a "oclusão" (senão param de desenhar quando a
// janela nasce escondida para a animação de abrir e ficam parados)
- if (LaunchNoOcclusion(target, args, a.exe.empty() ? *c : a.exe) || ActivatePackaged(target, args)) {
+ if (apps::LaunchNoOcclusion(target, args, a.exe.empty() ? *c : a.exe) || apps::ActivatePackaged(target, args)) {
Log(L"dock: abrindo %ls (pacote %ls)", a.name.c_str(), aumid.c_str());
return;
}
}
if (shell::OpenCalculator(a.id + L"|" + a.launch + L"|" + a.exe)) return; // a Calculadora do Windows fixada: abre a nossa
- if (LaunchNoOcclusion(a.launch, args, a.exe)) return;
+ if (apps::LaunchNoOcclusion(a.launch, args, a.exe)) return;
std::wstring lower = a.launch + L"|" + a.exe;
for (auto& ch : lower) ch = towlower(ch);
if (lower.find(L"immersivecontrolpanel") != std::wstring::npos || lower.find(L"systemsettings.exe") != std::wstring::npos) {
shell::OpenSettings(L""); // Ajustes do Windows fixado no Dock: abre o nosso
return;
}
- if (ActivatePackaged(a.launch, args)) { Log(L"dock: abrindo %ls", a.name.c_str()); return; } // empacotado: sem segurar a interface
- ShellExecuteW(nullptr, L"open", a.launch.c_str(), args.empty() ? nullptr : args.c_str(), nullptr, SW_SHOWNORMAL);
+ if (apps::ActivatePackaged(a.launch, args)) { Log(L"dock: abrindo %ls", a.name.c_str()); return; } // empacotado: sem segurar a interface
+ ShellExecuteW(nullptr, L"open", a.launch.c_str(), args.empty() ? nullptr : args.c_str(), nullptr, SW_SHOWNORMAL); // já numa thread
Log(L"dock: abrindo %ls", a.name.c_str());
}
@@ -1032,7 +1059,7 @@ void apps::Activate(App& a) {
std::vector<HWND> back;
for (auto& w : a.wins) if (IsHidden(w.hwnd)) back.push_back(w.hwnd);
if (!back.empty()) {
- for (int i = (int)back.size() - 1; i >= 0; i--) { g_hiddenWins.erase(back[i]); ShowWindow(back[i], SW_SHOWNOACTIVATE); }
+ for (int i = (int)back.size() - 1; i >= 0; i--) { g_hiddenWins.erase(back[i]); ShowWindowAsync(back[i], SW_SHOWNOACTIVATE); }
ForceForeground(back[0]);
Log(L"dock: %ls volta (%zu janelas)", a.name.c_str(), back.size());
return;
@@ -1046,7 +1073,7 @@ void apps::Activate(App& a) {
return;
}
for (int i = (int)a.wins.size() - 1; i >= 0; i--) // de trás para frente: a ordem entre elas se mantém
- if (!a.wins[i].minimized) SetWindowPos(a.wins[i].hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ if (!a.wins[i].minimized) SetWindowPos(a.wins[i].hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
for (auto& w : a.wins) if (!w.minimized) { ForceForeground(w.hwnd); break; }
}
@@ -1054,7 +1081,18 @@ void apps::Hide(App& a) {
DWORD now = GetTickCount();
std::vector<HWND> hs;
for (auto& w : a.wins) if (!w.minimized && !IsIconic(w.hwnd)) { g_hiddenWins[w.hwnd] = now; hs.push_back(w.hwnd); }
- for (HWND h : hs) ShowWindow(h, SW_MINIMIZE); // somem na hora (a animação do Windows está desligada); a frente passa para o app de trás
+ // assíncrono: o ShowWindow numa janela de outro programa espera a thread dela (app ocupado = Shell parado, issue #32)
+ for (HWND h : hs) ShowWindowAsync(h, SW_MINIMIZE); // somem na hora (a animação do Windows está desligada)
+ // a frente passa para a janela de cima de outro app, como no Mac. Minimizada por fora, a janela continuava sendo a
+ // "da frente" para o Windows (medido: minimizada e ainda em primeiro plano), com o teclado num app que sumiu.
+ struct Ctx { const std::vector<HWND>* hs; HWND next; } cx{ &hs, nullptr };
+ EnumWindows([](HWND h, LPARAM l) -> BOOL {
+ auto* c = (Ctx*)l;
+ if (std::find(c->hs->begin(), c->hs->end(), h) != c->hs->end() || IsIconic(h) || !IsTaskbarWindow(h)) return TRUE;
+ c->next = h;
+ return FALSE;
+ }, (LPARAM)&cx);
+ if (cx.next) SetForegroundWindow(cx.next);
Log(L"dock: %ls oculto (%zu janelas)", a.name.c_str(), hs.size());
}
// Encerrar = como o "Finalizar tarefa": mata os processos das janelas do app na hora, sem perguntar.
@@ -1188,5 +1226,5 @@ void apps::ShowInFinder(const App& a) {
std::wstring aumid; ReadLink(a.launch, target, aumid);
}
if (target.empty()) target = a.launch;
- ShellExecuteW(nullptr, L"open", g_finderExe.c_str(), (L"\"" + target + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", g_finderExe.c_str(), (L"\"" + target + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
}
diff --git a/src/shell/atalhos.cpp b/src/shell/atalhos.cpp
index 71e77b8..2386c48 100644
--- a/src/shell/atalhos.cpp
+++ b/src/shell/atalhos.cpp
@@ -428,8 +428,8 @@ void atalhos::MediaCommand(const std::wstring& exePath, const std::wstring& aumi
}
void atalhos::Run(const Item& it) {
- if (it.recent) { ShellExecuteW(nullptr, L"open", it.path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return; }
- ShellExecuteW(nullptr, L"open", it.path.c_str(), it.args.empty() ? nullptr : it.args.c_str(), it.dir.empty() ? nullptr : it.dir.c_str(), SW_SHOWNORMAL);
+ if (it.recent) { shell::Abrir(L"open", it.path.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return; }
+ shell::Abrir(L"open", it.path.c_str(), it.args.empty() ? nullptr : it.args.c_str(), it.dir.empty() ? nullptr : it.dir.c_str(), SW_SHOWNORMAL);
Log(L"atalhos: \"%ls\" (%ls %ls)", it.title.c_str(), it.path.c_str(), it.args.c_str());
}
diff --git a/src/shell/central.cpp b/src/shell/central.cpp
index 97edaf4..e0fe5f3 100644
--- a/src/shell/central.cpp
+++ b/src/shell/central.cpp
@@ -1931,7 +1931,7 @@ void ToggleCtl(const std::wstring& id) {
}
void RunExtra(const std::wstring& id) { // controle da galeria clicado (fora da edição)
Close();
- auto open = [](const std::wstring& t, const wchar_t* args = nullptr) { ShellExecuteW(nullptr, L"open", t.c_str(), args, nullptr, SW_SHOWNORMAL); };
+ auto open = [](const std::wstring& t, const wchar_t* args = nullptr) { shell::Abrir(L"open", t.c_str(), args, nullptr, SW_SHOWNORMAL); };
if (id == L"calculadora") open(shell::dir + L"\\" EXE_CALCULATOR);
else if (id == L"terminal") open(shell::dir + L"\\" EXE_TERMINAL);
else if (id == L"monitor") shell::OpenMonitor();
@@ -2016,7 +2016,7 @@ void Click(D2D1_POINT_2F p) {
OpenSettings(pg[g_detail]); return;
}
case H_DET_ROW:
- if (g_detail == D_WIFI) { if (hit->arg >= 0) { Close(); ShellExecuteW(nullptr, L"open", L"ms-availablenetworks:", nullptr, nullptr, SW_SHOWNORMAL); } else OpenSettings(L"wifi"); return; }
+ if (g_detail == D_WIFI) { if (hit->arg >= 0) { Close(); shell::Abrir(L"open", L"ms-availablenetworks:", nullptr, nullptr, SW_SHOWNORMAL); } else OpenSettings(L"wifi"); return; }
if (g_detail == D_BT) { OpenSettings(L"bluetooth"); return; }
if (g_detail == D_FOCO) { // um modo: liga o Foco (notificações silenciadas) nele; o mesmo de novo desliga
int cur = FocoModo(st0.focus);
@@ -2038,7 +2038,7 @@ void Click(D2D1_POINT_2F p) {
Paint(); return;
}
return;
- case H_NIGHT: Close(); ShellExecuteW(nullptr, L"open", L"ms-settings:nightlight", nullptr, nullptr, SW_SHOWNORMAL); return;
+ case H_NIGHT: Close(); shell::Abrir(L"open", L"ms-settings:nightlight", nullptr, nullptr, SW_SHOWNORMAL); return;
case H_DET_PANEL: return;
default: break; // brilho, volume, Modo Escuro: o mesmo dos blocos
}
@@ -2070,7 +2070,7 @@ void Click(D2D1_POINT_2F p) {
case H_WIFI: if (Tahoe()) { OpenDetail(D_WIFI, hit->r); Paint(); return; } OpenSettings(L"wifi"); return;
case H_BT: if (Tahoe()) { OpenDetail(D_BT, hit->r); Paint(); return; } OpenSettings(L"bluetooth"); return;
case H_FOCUS_TEXT: OpenDetail(D_FOCO, hit->r); Paint(); return;
- case H_AIRDROP: Close(); ShellExecuteW(nullptr, L"open", L"ms-settings:crossdevice", nullptr, nullptr, SW_SHOWNORMAL); return;
+ case H_AIRDROP: Close(); shell::Abrir(L"open", L"ms-settings:crossdevice", nullptr, nullptr, SW_SHOWNORMAL); return;
case H_FOCUS: { // Foco = notificações silenciadas
DWORD v = st.focus ? 1 : 0;
RegSetKeyValueW(HKEY_CURRENT_USER, PUSH, L"ToastEnabled", REG_DWORD, &v, sizeof(v));
@@ -2140,7 +2140,7 @@ void Click(D2D1_POINT_2F p) {
DWORD pid = 0; GetWindowThreadProcessId(w, &pid);
AllowSetForegroundWindow(pid);
PostMessageW(w, msg, 5, 0);
- } else ShellExecuteW(nullptr, L"open", (shell::dir + L"\\" EXE_SCREENSHOT).c_str(), L"/5", nullptr, SW_SHOWNORMAL);
+ } else shell::Abrir(L"open", (shell::dir + L"\\" EXE_SCREENSHOT).c_str(), L"/5", nullptr, SW_SHOWNORMAL);
return;
}
default: break;
diff --git a/src/shell/dock.cpp b/src/shell/dock.cpp
index 4939da9..a3c078f 100644
--- a/src/shell/dock.cpp
+++ b/src/shell/dock.cpp
@@ -139,6 +139,32 @@ bool g_hidden = false; // ocultação automática: escondido agora
float g_reveal = 1; // 0 = escondido, 1 = à mostra (animação)
D2D1_RECT_F g_bg; // fundo atual (pt, coordenadas da janela dos ícones)
bool g_trashFull = false;
+
+// Lixeira cheia ou vazia, numa thread: o SHQueryRecycleBin passa pela lixeira de todos os discos (HD externo
+// dormindo, unidade de rede) e segurou a interface do Shell por 10,2 s a cada BuildItems (pilha de 22/11/2026
+// 19:54, issue #32: "o Shell inteiro congela"). Uma consulta por vez; pedido no meio dela refaz no fim.
+std::atomic<bool> g_lixeiraRodando{ false }, g_lixeiraDeNovo{ false };
+void Paint();
+void PedirLixeira() {
+ if (g_lixeiraRodando.exchange(true)) { g_lixeiraDeNovo = true; return; }
+ std::thread([] {
+ HRESULT ci = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
+ bool cheia;
+ do {
+ g_lixeiraDeNovo = false;
+ DWORD t0 = GetTickCount();
+ SHQUERYRBINFO q{ sizeof(q) };
+ cheia = SUCCEEDED(SHQueryRecycleBinW(nullptr, &q)) && q.i64NumItems > 0;
+ if (DWORD ms = GetTickCount() - t0; ms > 500) Log(L"dock: a Lixeira levou %lu ms para responder (fora da interface)", ms);
+ } while (g_lixeiraDeNovo);
+ if (SUCCEEDED(ci)) CoUninitialize();
+ shell::NaInterface([cheia] {
+ g_lixeiraRodando = false;
+ if (g_lixeiraDeNovo.exchange(false)) PedirLixeira();
+ if (cheia != g_trashFull) { g_trashFull = cheia; Paint(); }
+ });
+ }).detach();
+}
int g_dropHit = -1;
void LeftClick(int i);
@@ -333,8 +359,7 @@ void BuildItems() {
else ++it;
}
g_items.push_back({ I_TRASH, -1 });
- SHQUERYRBINFO q{ sizeof(q) };
- g_trashFull = SUCCEEDED(SHQueryRecycleBinW(nullptr, &q)) && q.i64NumItems > 0;
+ PedirLixeira();
FitTile();
}
@@ -1268,7 +1293,7 @@ int HitTest(float x, float y) {
// ---- menus de botão direito
void OpenFinder(const std::wstring& args) {
if (shell::nativo) { shell::AbrirFinder(args); return; }
- for (auto& a : apps::list) if (a.finder) { ShellExecuteW(nullptr, L"open", a.launch.c_str(), args.c_str(), nullptr, SW_SHOWNORMAL); return; }
+ for (auto& a : apps::list) if (a.finder) { shell::Abrir(L"open", a.launch.c_str(), args.c_str(), nullptr, SW_SHOWNORMAL); return; }
}
ctxmenu::Item MI(const std::wstring& l, int id, bool checked = false, bool disabled = false) {
@@ -1483,8 +1508,18 @@ void LeftClick(int i) {
App& a = apps::list[it.app];
// o app já está na frente: o clique oculta (as janelas somem e voltam no próximo clique)
HWND fg = GetForegroundWindow();
+ HWND fgDono = fg ? GetAncestor(fg, GA_ROOTOWNER) : nullptr; // diálogo ou janela de ferramenta do app: vale a dona
bool front = false;
- for (auto& w : a.wins) if (w.hwnd == fg && !IsIconic(fg)) front = true;
+ for (auto& w : a.wins) if ((w.hwnd == fg || w.hwnd == fgDono) && !IsIconic(w.hwnd)) front = true;
+ // a janela da frente é do app mas não está na lista do Dock (janela sem título, a "barra própria" de alguns
+ // apps, outra janela do mesmo processo): também conta (issue #29: "clicar no ícone não minimiza")
+ if (!front && fg && !IsIconic(fg) && !apps::IsShellWindow(fg) && !a.wins.empty() && apps::OfWindow(fgDono ? fgDono : fg) == &a) front = true;
+ if (!front && !a.wins.empty() && !(fg && IsIconic(fg))) { // diagnóstico: por que o clique ativa em vez de ocultar (só classes, sem títulos)
+ wchar_t c1[64] = L"-", c2[64] = L"-";
+ if (fg) GetClassNameW(fg, c1, 64);
+ if (fgDono && fgDono != fg) GetClassNameW(fgDono, c2, 64);
+ Log(L"dock: clique em %ls ativa (frente: %ls, dona %ls; %zu janelas do app)", a.name.c_str(), c1, c2, a.wins.size());
+ }
if (front && shell::Setting(L"dock_clique_oculta", L"1") == L"1") { apps::Hide(a); apps::Refresh(); BuildItems(); Paint(); return; }
if (g_minNoIcone && !a.wins.empty()) { // minimizadas no ícone: tudo minimizado, a mais recente sai do ícone pelo funil
bool anyShown = false;
@@ -1511,7 +1546,7 @@ void LeftClick(int i) {
m.push_back(MI(Tr(L"Abrir no Finder"), 30));
int id = ShowMenu(i, m);
if (id == 30) OpenFinder(L"shell:Downloads");
- else if (id >= 5000 && id - 5000 < (int)files.size()) ShellExecuteW(nullptr, L"open", files[id - 5000].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ else if (id >= 5000 && id - 5000 < (int)files.size()) shell::Abrir(L"open", files[id - 5000].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
}
@@ -1611,6 +1646,20 @@ struct DockDrop : IDropTarget {
LRESULT CALLBACK IconsProc(HWND h, UINT m, WPARAM w, LPARAM l) {
float sc = Sc();
+ // teste (clicar no ícone sem mexer no mouse do PC): wParam = uma janela; devolve o meio do ícone do app dela em
+ // coordenadas desta janela (MAKELONG), ou -1. Quem testa posta WM_LBUTTONDOWN/UP ali.
+ static UINT testeIcone = RegisterWindowMessageW(L"ShellDockTesteIcone");
+ if (m == testeIcone && testeIcone) {
+ for (auto& it : g_items) {
+ if (it.kind != I_APP || it.app < 0 || it.app >= (int)apps::list.size()) continue;
+ for (auto& win : apps::list[it.app].wins)
+ if (win.hwnd == (HWND)w) {
+ D2D1_POINT_2F p = ToWin(it.cx, g_bg.top + PAD_TOP + g_tile / 2);
+ return MAKELONG((int)std::lround(p.x * sc), (int)std::lround(p.y * sc));
+ }
+ }
+ return -1;
+ }
switch (m) {
case WM_MOUSEACTIVATE: return MA_NOACTIVATE;
case WM_SETCURSOR:
diff --git a/src/shell/ilha.cpp b/src/shell/ilha.cpp
index 0d84625..47f97cc 100644
--- a/src/shell/ilha.cpp
+++ b/src/shell/ilha.cpp
@@ -1744,7 +1744,7 @@ void Activate(const std::wstring& aumid) { // traz o app que está tocando
apps::Activate(a); return;
}
if (aumid.find(L'!') != std::wstring::npos && !apps::ActivatePackaged(L"shell:AppsFolder\\" + aumid))
- ShellExecuteW(nullptr, L"open", (L"shell:AppsFolder\\" + aumid).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", (L"shell:AppsFolder\\" + aumid).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
void Close() { g_openOn = false; KillTimer(g_wnd, TM_LEAVE); Update(); }
@@ -1797,7 +1797,7 @@ void ClickHit(const Hit& h, D2D1_POINT_2F p) {
break;
case H_CLIPCLR: g_clips.clear(); g_clipTop = 0; SaveClips(); break;
case H_SHELF:
- if (h.arg < (int)g_shelf.size()) ShellExecuteW(nullptr, L"open", g_shelf[h.arg].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ if (h.arg < (int)g_shelf.size()) shell::Abrir(L"open", g_shelf[h.arg].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
break;
case H_SHELFCLR: g_shelf.clear(); ShelfSave(); break;
default: break;
@@ -1845,7 +1845,7 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
pk.title = Tr(L"Download concluído");
pk.sub = full.substr(full.find_last_of(L'\\') + 1);
pk.glyph = 0xE896; pk.color = D2D1::ColorF(0.35f, 0.65f, 1.f, 1);
- pk.click = [full] { ShellExecuteW(nullptr, L"open", L"explorer.exe", (L"/select,\"" + full + L"\"").c_str(), nullptr, SW_SHOWNORMAL); };
+ pk.click = [full] { shell::Abrir(L"open", L"explorer.exe", (L"/select,\"" + full + L"\"").c_str(), nullptr, SW_SHOWNORMAL); };
ShowPeek(pk, 4000);
}
return 0;
diff --git a/src/shell/janelas.cpp b/src/shell/janelas.cpp
index e07f811..d9949d7 100644
--- a/src/shell/janelas.cpp
+++ b/src/shell/janelas.cpp
@@ -17,6 +17,7 @@
#include <shlobj.h>
#include <map>
#include <set>
+#include <thread>
namespace {
@@ -441,12 +442,16 @@ void janelas::Start() {
// programas de 32 bits: a DLL de 32 bits fica no rundll32.exe de 32 bits do Windows (entrada WacOSHost, ver
// macjanela.cpp), que recebe os pedidos de gancho pela janela "MacJanela32Host" (e põe o gancho com a carregadora de 32)
if (tem32 && !FindWindowExW(HWND_MESSAGE, nullptr, L"MacJanela32Host", nullptr) && !copy32.empty()) {
- STARTUPINFOW si{ sizeof(si) }; PROCESS_INFORMATION pi{};
+ // numa thread: abrir o processo e esperar ele ficar pronto parou a interface 2,9 s ao iniciar com o disco
+ // ocupado (pilha de 22/11/2026 20:01, issue #32). Pronto o hospedeiro, as janelas de 32 bits já abertas são revistas.
std::wstring cmd = L"\"" + std::wstring(wow) + L"\\rundll32.exe\" \"" + copy32 + L"\",WacOSHost";
- if (CreateProcessW(nullptr, cmd.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) {
- WaitForInputIdle(pi.hProcess, 2000);
+ std::thread([cmd]() mutable {
+ STARTUPINFOW si{ sizeof(si) }; PROCESS_INFORMATION pi{};
+ if (!CreateProcessW(nullptr, cmd.data(), nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi)) return;
+ WaitForInputIdle(pi.hProcess, 5000);
CloseHandle(pi.hProcess); CloseHandle(pi.hThread);
- }
+ shell::NaInterface([] { if (g_proc) EnumWindows([](HWND h, LPARAM) -> BOOL { Consider(h); return TRUE; }, 0); });
+ }).detach();
}
g_ev = SetWinEventHook(EVENT_OBJECT_SHOW, EVENT_OBJECT_SHOW, nullptr, OnEvent, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
g_evCreate = SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, nullptr, OnCreate, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
diff --git a/src/shell/main.cpp b/src/shell/main.cpp
index 2de446e..a1ca1f9 100644
--- a/src/shell/main.cpp
+++ b/src/shell/main.cpp
@@ -356,7 +356,7 @@ bool shell::OpenCalculator(const std::wstring& target) {
if (!calc) return false;
std::wstring exe = shell::dir + L"\\" EXE_CALCULATOR;
if (GetFileAttributesW(exe.c_str()) == INVALID_FILE_ATTRIBUTES) return false;
- ShellExecuteW(nullptr, L"open", exe.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str());
return true;
}
@@ -364,7 +364,7 @@ bool shell::OpenCalculator(const std::wstring& target) {
void shell::OpenMonitor() {
std::wstring exe = shell::dir + L"\\" EXE_MONITOR;
if (GetFileAttributesW(exe.c_str()) == INVALID_FILE_ATTRIBUTES) exe = L"taskmgr.exe";
- ShellExecuteW(nullptr, L"open", exe.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
// Forçar Encerrar Aplicativos (WacOSForceQuit.exe); sem ele, o Monitor de Atividade
@@ -372,7 +372,7 @@ void shell::OpenForceQuit(bool memory) {
std::wstring exe = shell::dir + L"\\" EXE_FORCEQUIT;
if (GetFileAttributesW(exe.c_str()) == INVALID_FILE_ATTRIBUTES) { shell::OpenMonitor(); return; }
AllowSetForegroundWindow(ASFW_ANY); // aberta pela pressão de memória, sem clique: precisa vir para a frente
- ShellExecuteW(nullptr, L"open", exe.c_str(), memory ? L"--memoria" : nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str(), memory ? L"--memoria" : nullptr, nullptr, SW_SHOWNORMAL);
}
void shell::Sound(const wchar_t* name) {
@@ -382,7 +382,35 @@ void shell::Sound(const wchar_t* name) {
void shell::OpenSettings(const std::wstring& page) {
std::wstring args = page.empty() ? L"" : (page.rfind(L"ms-settings:", 0) == 0 ? page : L"--pagina=" + page);
- ShellExecuteW(nullptr, L"open", (shell::dir + L"\\" EXE_SETTINGS).c_str(), args.c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", (shell::dir + L"\\" EXE_SETTINGS).c_str(), args.c_str());
+}
+
+// ShellExecute numa thread: na thread da interface ele chegou a segurar o Shell 3,2 s (abrir o Ajustes pela Ilha com o
+// disco ocupado; pilha de 22/11/2026 19:54, issue #32). A thread espera o ShellExecute terminar (SEE_MASK_NOASYNC).
+void shell::Abrir(const wchar_t* verb, const wchar_t* file, const wchar_t* args, const wchar_t* dir, int show) {
+ if (!file) return;
+ AllowSetForegroundWindow(ASFW_ANY); // o app aberto pela thread vem para a frente como antes
+ std::wstring v = verb ? verb : L"", f = file, a = args ? args : L"", d = dir ? dir : L"";
+ bool temVerbo = verb != nullptr;
+ std::thread([v, f, a, d, show, temVerbo] {
+ HRESULT ci = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
+ SHELLEXECUTEINFOW se{ sizeof(se) };
+ se.fMask = SEE_MASK_NOASYNC;
+ se.lpVerb = temVerbo ? v.c_str() : nullptr;
+ se.lpFile = f.c_str();
+ se.lpParameters = a.empty() ? nullptr : a.c_str();
+ se.lpDirectory = d.empty() ? nullptr : d.c_str();
+ se.nShow = show;
+ if (!ShellExecuteExW(&se)) Log(L"abrir: não abriu %ls (%lu)", f.c_str(), GetLastError());
+ if (SUCCEEDED(ci)) CoUninitialize();
+ }).detach();
+}
+
+// trabalho feito numa thread devolve o resultado para a interface (dock: a Lixeira cheia ou vazia)
+static const UINT WM_NA_INTERFACE = WM_APP + 60;
+void shell::NaInterface(std::function<void()> f) {
+ auto* p = new std::function<void()>(std::move(f));
+ if (!g_msg || !PostMessageW(g_msg, WM_NA_INTERFACE, 0, (LPARAM)p)) delete p;
}
static void LoadSettings() {
@@ -596,7 +624,7 @@ static void Screenshot(int kind, bool clip) {
return;
}
std::wstring args = L"/" + std::to_wstring(kind) + (clip ? L" /c" : L"");
- ShellExecuteW(nullptr, L"open", (shell::dir + L"\\" EXE_SCREENSHOT).c_str(), args.c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", (shell::dir + L"\\" EXE_SCREENSHOT).c_str(), args.c_str(), nullptr, SW_SHOWNORMAL);
Log(L"Captura de Tela aberta agora (%ls)", args.c_str());
}
@@ -607,7 +635,7 @@ void shell::AbrirFinder(const std::wstring& args) {
if (pedir && pedir(args.c_str())) { Log(L"Finder (nativo): %ls", args.c_str()); return; }
Log(L"Finder nativo indisponível, abrindo o exe: %ls", args.c_str());
}
- ShellExecuteW(nullptr, L"open", (shell::dir + L"\\" EXE_FINDER).c_str(), args.c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", (shell::dir + L"\\" EXE_FINDER).c_str(), args.c_str(), nullptr, SW_SHOWNORMAL);
}
static void EnsureReserve() {
@@ -736,6 +764,7 @@ static void AutoAppearance() {
}
static LRESULT CALLBACK MsgProc(HWND h, UINT m, WPARAM w, LPARAM l) {
+ if (m == WM_NA_INTERFACE) { auto* p = (std::function<void()>*)l; if (p) { (*p)(); delete p; } return 0; }
// Outro programa (o Explorador, com a barra do Windows escondida ou em ocultar automaticamente) devolveu a área de
// trabalho para a tela inteira: reaplica a nossa NA HORA. Antes esperava o tique de 1 s, e nesse meio-tempo as
// janelas maximizadas e os ícones da mesa subiam para baixo da barra de menus e voltavam (issue #1: "a área
@@ -1119,7 +1148,7 @@ int WINAPI wWinMain(HINSTANCE hi, HINSTANCE, PWSTR, int) {
std::wstring finder = shell::dir + L"\\" EXE_FINDER;
if (GetFileAttributesW(finder.c_str()) != INVALID_FILE_ATTRIBUTES) {
shell::SetSetting(L"finder_padrao", L"1");
- ShellExecuteW(nullptr, L"open", finder.c_str(), L"--quieto --padrao on", nullptr, SW_HIDE);
+ shell::Abrir(L"open", finder.c_str(), L"--quieto --padrao on", nullptr, SW_HIDE);
Log(L"finder: de volta depois do Desligar (finder_padrao=1, --padrao on)");
}
}
@@ -1193,7 +1222,8 @@ int WINAPI wWinMain(HINSTANCE hi, HINSTANCE, PWSTR, int) {
PreloadApps();
MSG msg;
- while (GetMessageW(&msg, nullptr, 0, 0)) { mesa::Pulse(); TranslateMessage(&msg); DispatchMessageW(&msg); } // pulso: ver mesa::Pulse
+ sentinela::Start(g_msg); // interface parada 1 s ou mais: o shell.log diz onde (issue #32)
+ while (GetMessageW(&msg, nullptr, 0, 0)) { mesa::Pulse(); sentinela::ultimaMsg = msg.message; sentinela::ultimaJanela = msg.hwnd; TranslateMessage(&msg); DispatchMessageW(&msg); } // pulso: ver mesa::Pulse
Restore();
DeregisterShellHookWindow(g_msg);
// Sai daqui direto (TerminateProcess), com tudo já devolvido ao Windows. Voltar do wWinMain roda o
@@ -1283,7 +1313,8 @@ int shell::RodarNativo(HINSTANCE hi, const std::wstring& dirBin, const std::wstr
PreloadApps();
MSG msg;
- while (GetMessageW(&msg, nullptr, 0, 0)) { mesa::Pulse(); TranslateMessage(&msg); DispatchMessageW(&msg); } // pulso: ver mesa::Pulse
+ sentinela::Start(g_msg); // interface parada 1 s ou mais: o shell.log diz onde (issue #32)
+ while (GetMessageW(&msg, nullptr, 0, 0)) { mesa::Pulse(); sentinela::ultimaMsg = msg.message; sentinela::ultimaJanela = msg.hwnd; TranslateMessage(&msg); DispatchMessageW(&msg); } // pulso: ver mesa::Pulse
Restore();
DeregisterShellHookWindow(g_msg);
Log(L"Shell nativo encerrado");
diff --git a/src/shell/menubar.cpp b/src/shell/menubar.cpp
index 04ca586..ab4021d 100644
--- a/src/shell/menubar.cpp
+++ b/src/shell/menubar.cpp
@@ -1185,12 +1185,12 @@ void Shutdown(UINT how) {
void Open(const wchar_t* what, const wchar_t* args = nullptr) {
if (!wcsncmp(what, L"ms-settings:", 12)) { shell::OpenSettings(what); return; } // o nosso Ajustes do Sistema
- ShellExecuteW(nullptr, L"open", what, args, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", what, args, nullptr, SW_SHOWNORMAL);
}
void OpenFinder(const std::wstring& args) {
if (shell::nativo) { shell::AbrirFinder(args); return; }
- for (auto& a : apps::list) if (a.finder) { ShellExecuteW(nullptr, L"open", a.launch.c_str(), args.c_str(), nullptr, SW_SHOWNORMAL); return; }
+ for (auto& a : apps::list) if (a.finder) { shell::Abrir(L"open", a.launch.c_str(), args.c_str(), nullptr, SW_SHOWNORMAL); return; }
}
void Run(int id, App* app) {
@@ -1214,7 +1214,7 @@ void Run(int id, App* app) {
case 107: bloqueio::Lock(); break; // a nossa tela de bloqueio (o LockWorkStation fica desligado pela política enquanto o Shell roda: não fazia nada, issue #8)
case 108: alertas::Confirm(Tr(L"Tem certeza de que deseja encerrar todos os aplicativos e sair agora?"), L"", Tr(L"Encerrar Sessão"), [] { ExitWindowsEx(EWX_LOGOFF, 0); }, IconePC()); break;
case 109: shell::Quit(L"menu do logo"); break;
- case 200: if (app && !app->exe.empty()) ShellExecuteW(nullptr, L"properties", app->exe.c_str(), nullptr, nullptr, SW_SHOWNORMAL); break;
+ case 200: if (app && !app->exe.empty()) shell::Abrir(L"properties", app->exe.c_str(), nullptr, nullptr, SW_SHOWNORMAL); break;
case 201: if (app) apps::Hide(*app); break;
case 202: for (auto& a : apps::list) if (&a != app) apps::Hide(a); break;
case 203: for (auto& a : apps::list) for (auto& w : a.wins) if (w.minimized) ShowWindow(w.hwnd, SW_SHOWNOACTIVATE); break;
diff --git a/src/shell/mesa.cpp b/src/shell/mesa.cpp
index dbdb652..b7487f2 100644
--- a/src/shell/mesa.cpp
+++ b/src/shell/mesa.cpp
@@ -936,7 +936,7 @@ void OpenItem(const Item& it) {
}
std::wstring finder = shell::dir + L"\\" EXE_FINDER;
if (dir && GetFileAttributesW(finder.c_str()) != INVALID_FILE_ATTRIBUTES) {
- ShellExecuteW(nullptr, L"open", finder.c_str(), (L"\"" + target + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", finder.c_str(), (L"\"" + target + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
return;
}
if (shell::OpenCalculator(it.path)) return;
@@ -2025,9 +2025,9 @@ void mesa::WinKey(UINT vk) {
if (vk == 'E') {
std::wstring finder = shell::dir + L"\\" EXE_FINDER;
bool usaFinder = shell::Setting(L"finder_padrao", L"1") == L"1" && GetFileAttributesW(finder.c_str()) != INVALID_FILE_ATTRIBUTES;
- if (!usaFinder && !Standalone()) { ShellExecuteW(nullptr, L"open", L"explorer.exe", nullptr, nullptr, SW_SHOWNORMAL); return; }
+ if (!usaFinder && !Standalone()) { shell::Abrir(L"open", L"explorer.exe", nullptr, nullptr, SW_SHOWNORMAL); return; }
AllowSetForegroundWindow(ASFW_ANY);
- ShellExecuteW(nullptr, L"open", finder.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", finder.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
} else if (vk == 'R') { // Executar (shell32 #61), no próprio Shell
typedef void(WINAPI * RunFileDlgFn)(HWND, HICON, LPCWSTR, LPCWSTR, LPCWSTR, UINT);
auto f = (RunFileDlgFn)GetProcAddress(GetModuleHandleW(L"shell32.dll"), MAKEINTRESOURCEA(61));
diff --git a/src/shell/missioncontrol.cpp b/src/shell/missioncontrol.cpp
index d4616ea..3d52318 100644
--- a/src/shell/missioncontrol.cpp
+++ b/src/shell/missioncontrol.cpp
@@ -551,6 +551,10 @@ bool CompInit() {
return true;
}
+// pixels do papel de parede lidos numa thread pelo Warm (o LoadPng na interface parou o Shell 15 e 21 s com o disco
+// ocupado; pilhas de 22/11/2026 20:02 e 20:11, issue #32). O CompWall usa e solta.
+std::mutex g_wcMx; std::wstring g_wcPath; UINT g_wcW, g_wcH; std::vector<BYTE> g_wcPx;
+
// papel de parede (cobrindo a tela) numa superfície parada: desenhado uma vez por papel e tamanho
void CompWall(const std::wstring& path) {
g_blackSc->SetScaleX(W()); g_blackSc->SetScaleY(H());
@@ -560,7 +564,11 @@ void CompWall(const std::wstring& path) {
g_wallSurf = ui::CompSurface((int)W(), (int)H(), [&](ID2D1DeviceContext* dc) {
ID2D1Bitmap* wall = nullptr;
UINT ww = 0, wh = 0; std::vector<BYTE> px;
- if (!path.empty() && ui::LoadPng(path, ww, wh, px)) wall = ui::Bitmap(dc, ww, wh, px);
+ {
+ std::lock_guard<std::mutex> lk(g_wcMx);
+ if (g_wcPath == path && !g_wcPx.empty()) { wall = ui::Bitmap(dc, g_wcW, g_wcH, g_wcPx); g_wcPx.clear(); g_wcPx.shrink_to_fit(); g_wcPath.clear(); }
+ }
+ if (!wall && !path.empty() && ui::LoadPng(path, ww, wh, px)) wall = ui::Bitmap(dc, ww, wh, px);
if (wall) {
auto s = wall->GetSize();
float k = std::max(W() / s.width, H() / s.height);
@@ -1036,7 +1044,27 @@ void missioncontrol::Warm() {
SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, path, 0);
double t0 = anim::Now();
LoadDeskWall(path);
- if (shell::Setting(L"mc_motor", L"composicao") == L"composicao" && CompInit()) CompWall(path);
+ if (shell::Setting(L"mc_motor", L"composicao") == L"composicao" && CompInit()) {
+ std::wstring p = path;
+ std::thread([p] { // ler e decodificar o arquivo fora da interface; desenhar na superfície, nela
+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);
+ HRESULT ci = CoInitializeEx(nullptr, COINIT_MULTITHREADED); // WIC
+ UINT ww = 0, wh = 0; std::vector<BYTE> px;
+ double t1 = anim::Now();
+ bool ok = !p.empty() && ui::LoadPng(p, ww, wh, px);
+ if (SUCCEEDED(ci)) CoUninitialize();
+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
+ if (ok) { std::lock_guard<std::mutex> lk(g_wcMx); g_wcPath = p; g_wcW = ww; g_wcH = wh; g_wcPx = std::move(px); }
+ double lido = anim::Now() - t1;
+ shell::NaInterface([p, lido] {
+ if (g_open) return;
+ double t2 = anim::Now();
+ CompWall(p);
+ { std::lock_guard<std::mutex> lk(g_wcMx); g_wcPx.clear(); g_wcPx.shrink_to_fit(); g_wcPath.clear(); } // já pronto: solta
+ Log(L"mission control: papel de parede lido em %.0f ms (fora da interface), desenhado em %.1f ms", lido, anim::Now() - t2);
+ });
+ }).detach();
+ }
Log(L"mission control: preparado antes de abrir em %.1f ms", anim::Now() - t0);
}
diff --git a/src/shell/notarapida.cpp b/src/shell/notarapida.cpp
index f15ca43..4045483 100644
--- a/src/shell/notarapida.cpp
+++ b/src/shell/notarapida.cpp
@@ -104,7 +104,7 @@ void OpenQuickNote() {
std::wstring exe = shell::dir + L"\\" EXE_NOTES;
if (GetFileAttributesW(exe.c_str()) == INVALID_FILE_ATTRIBUTES) { Log(L"nota rápida: " EXE_NOTES L" não encontrado"); return; }
AllowSetForegroundWindow(ASFW_ANY);
- ShellExecuteW(nullptr, L"open", exe.c_str(), L"--nota-rapida", shell::dir.c_str(), SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str(), L"--nota-rapida", shell::dir.c_str(), SW_SHOWNORMAL);
Log(L"nota rápida: aberta pelo canto");
}
diff --git a/src/shell/notificacoes.cpp b/src/shell/notificacoes.cpp
index 05332b4..3809a49 100644
--- a/src/shell/notificacoes.cpp
+++ b/src/shell/notificacoes.cpp
@@ -1013,12 +1013,12 @@ void DefaultWidgets() {
g_widgetKind.clear();
if (CentralOn(0)) {
g_widgets.push_back({ WIDGET_S, WIDGET_S, [](ID2D1DeviceContext* dc, float w, float h, bool d) { (liquid::Leopard() ? PaintCalendarLeo : PaintCalendar)(dc, w, h, d); },
- [] { ShellExecuteW(nullptr, L"open", L"outlookcal:", nullptr, nullptr, SW_SHOWNORMAL); } });
+ [] { shell::Abrir(L"open", L"outlookcal:", nullptr, nullptr, SW_SHOWNORMAL); } });
g_widgetKind.push_back(0);
}
if (CentralOn(1)) {
g_widgets.push_back({ WIDGET_S, WIDGET_S, [](ID2D1DeviceContext* dc, float w, float h, bool d) { (liquid::Leopard() ? PaintClockLeo : PaintClock)(dc, w, h, d); },
- [] { ShellExecuteW(nullptr, L"open", L"ms-clock:", nullptr, nullptr, SW_SHOWNORMAL); } });
+ [] { shell::Abrir(L"open", L"ms-clock:", nullptr, nullptr, SW_SHOWNORMAL); } });
g_widgetKind.push_back(1);
}
}
@@ -1272,7 +1272,7 @@ void OpenApp(const Note& n) {
for (auto& a : apps::list)
if (!_wcsicmp(a.name.c_str(), n.app.c_str())) { apps::Launch(a); return; }
if (!apps::ActivatePackaged(L"shell:AppsFolder\\" + n.aumid))
- ShellExecuteW(nullptr, L"open", (L"shell:AppsFolder\\" + n.aumid).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", (L"shell:AppsFolder\\" + n.aumid).c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
void ClearGroup(int gi) {
@@ -1397,7 +1397,7 @@ void Click(D2D1_POINT_2F p) {
WidgetsMenu(hit.r, -1); // Calendário e Relógio da Central; "Widgets da Mesa…" leva ao menu da mesa
return;
case A_SETTINGS: Close(); shell::OpenSettings(L"notificacoes"); return;
- case A_PERMISSION: Close(); ShellExecuteW(nullptr, L"open", L"ms-settings:privacy-notifications", nullptr, nullptr, SW_SHOWNORMAL); return;
+ case A_PERMISSION: Close(); shell::Abrir(L"open", L"ms-settings:privacy-notifications", nullptr, nullptr, SW_SHOWNORMAL); return;
case A_WIDGET:
if (hit.widget >= 0 && hit.widget < (int)g_widgets.size() && g_widgets[hit.widget].click) { auto f = g_widgets[hit.widget].click; Close(); f(); return; }
break;
@@ -1822,7 +1822,7 @@ LRESULT CALLBACK BannerProc(HWND h, UINT m, WPARAM w, LPARAM l) {
if (onX) { BannerOut(hv); return 0; } // fica na Central, como no Mac
Note n = g_bans[hv].n;
BannerOut(hv);
- if (n.id >= AVISO_ID) { ShellExecuteW(nullptr, L"open", n.aumid.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return 0; } // aviso do Lembretes/Calendário: abre o app
+ if (n.id >= AVISO_ID) { shell::Abrir(L"open", n.aumid.c_str(), nullptr, nullptr, SW_SHOWNORMAL); return 0; } // aviso do Lembretes/Calendário: abre o app
RemoveIds({ n.id }); OpenApp(n);
return 0;
}
diff --git a/src/shell/pastas.cpp b/src/shell/pastas.cpp
index 30ddac5..850768d 100644
--- a/src/shell/pastas.cpp
+++ b/src/shell/pastas.cpp
@@ -149,7 +149,7 @@ void Handle(HWND h) {
CoUninitialize();
return;
}
- ShellExecuteW(nullptr, L"open", exe.c_str(), (L"\"" + arg + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str(), (L"\"" + arg + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
HWND novo = nullptr;
for (int t = 0; t < 60 && !novo; t++) { // até 3 s
Sleep(50);
diff --git a/src/shell/pilhas.cpp b/src/shell/pilhas.cpp
index 19cb986..af3474c 100644
--- a/src/shell/pilhas.cpp
+++ b/src/shell/pilhas.cpp
@@ -347,7 +347,7 @@ int HitAt(LPARAM l) {
void OpenDownloadsInFinder() {
std::wstring finder = shell::dir + L"\\" EXE_FINDER;
- ShellExecuteW(nullptr, L"open", finder.c_str(), g_apps ? L"shell:Programs" : L"shell:Downloads", nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", finder.c_str(), g_apps ? L"shell:Programs" : L"shell:Downloads", nullptr, SW_SHOWNORMAL);
}
LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
@@ -380,7 +380,7 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
std::wstring p;
{ std::lock_guard<std::mutex> lk(g_mx); if (hv < (int)g_files.size()) p = g_files[hv].path; }
Hide();
- if (!p.empty() && !AbrirNoAppMac(p)) ShellExecuteW(nullptr, L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ if (!p.empty() && !AbrirNoAppMac(p)) shell::Abrir(L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
return 0;
}
@@ -527,7 +527,7 @@ void ShowList(POINT anchor) {
POINT pt = MenuPt(anchor, (int)std::lround((m.size() * 22 + 14) * Sc()));
int id = ctxmenu::ShowItems(g_wnd, pt, m);
if (id == 30) OpenDownloadsInFinder();
- else if (id >= 5000 && id - 5000 < (int)files.size() && !AbrirNoAppMac(files[id - 5000])) ShellExecuteW(nullptr, L"open", files[id - 5000].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ else if (id >= 5000 && id - 5000 < (int)files.size() && !AbrirNoAppMac(files[id - 5000])) shell::Abrir(L"open", files[id - 5000].c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
} // namespace
diff --git a/src/shell/quicklook.cpp b/src/shell/quicklook.cpp
index d0e36a1..01a7b02 100644
--- a/src/shell/quicklook.cpp
+++ b/src/shell/quicklook.cpp
@@ -422,8 +422,8 @@ std::wstring OwnApp(const std::wstring& p, std::wstring& name) {
return GetFileAttributesW(full.c_str()) != INVALID_FILE_ATTRIBUTES ? full : L"";
}
void OpenPath(const std::wstring& p) {
- if (!g_openExe.empty()) ShellExecuteW(nullptr, L"open", g_openExe.c_str(), (L"\"" + p + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
- else if (!shell::OpenCalculator(p)) ShellExecuteW(nullptr, L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ if (!g_openExe.empty()) shell::Abrir(L"open", g_openExe.c_str(), (L"\"" + p + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
+ else if (!shell::OpenCalculator(p)) shell::Abrir(L"open", p.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
}
std::wstring DefaultAppName(const std::wstring& p) {
diff --git a/src/shell/sentinela.cpp b/src/shell/sentinela.cpp
new file mode 100644
index 0000000..ee1b625
--- /dev/null
+++ b/src/shell/sentinela.cpp
@@ -0,0 +1,124 @@
+// Sentinela: a thread da interface do Shell parou (issue #32: "o Shell inteiro congela por um bom tempo")?
+// Uma thread própria manda WM_NULL para a janela de mensagens a cada 250 ms (SendMessageTimeout: responde
+// também dentro de menus e arrastos, que têm laço próprio). Sem resposta em 1 s, copia a pilha da thread da
+// interface (suspensa só durante a cópia: GetThreadContext + memcpy, nada que pegue trava) e, já solta, grava no
+// shell.log "interface parada" com a mensagem que estava sendo tratada, a janela e a pilha em módulo+deslocamento
+// (o deslocamento do WacOSShell.exe se resolve com o WacOSShell.pdb da mesma build). Quando volta, grava quanto
+// tempo ficou parada. No máximo 30 registros por execução.
+#include "shell.h"
+#include <algorithm>
+#include <thread>
+#include <atomic>
+
+namespace sentinela {
+std::atomic<UINT> ultimaMsg{ 0 };
+std::atomic<HWND> ultimaJanela{ nullptr };
+}
+
+namespace {
+
+HWND g_alvo;
+DWORD g_tid;
+const size_t COPIA = 96 * 1024; // o topo da pilha basta para as ~30 chamadas de cima
+BYTE g_copia[COPIA];
+
+// pilha da thread em `pcs` (endereços de retorno); devolve quantos
+int Pilha(HANDLE t, DWORD64* pcs, int max) {
+ CONTEXT c{}; c.ContextFlags = CONTEXT_FULL;
+ size_t n = 0;
+ DWORD64 orig = 0;
+ if (SuspendThread(t) == (DWORD)-1) return 0;
+ bool ok = GetThreadContext(t, &c) != FALSE;
+ if (ok) {
+ orig = c.Rsp;
+ MEMORY_BASIC_INFORMATION mbi{};
+ if (VirtualQuery((void*)orig, &mbi, sizeof(mbi))) {
+ DWORD64 fim = (DWORD64)mbi.BaseAddress + mbi.RegionSize;
+ n = (size_t)std::min<DWORD64>(COPIA, fim - orig);
+ memcpy(g_copia, (void*)orig, n);
+ }
+ }
+ ResumeThread(t);
+ if (!ok || !n) return 0;
+ const DWORD64 delta = (DWORD64)g_copia - orig;
+ auto mudar = [&](DWORD64& r) { if (r >= orig && r < orig + n) r += delta; };
+ auto dentro = [&](DWORD64 a) { return a >= (DWORD64)g_copia && a + 8 <= (DWORD64)g_copia + n; };
+ int k = 0;
+ __try {
+ mudar(c.Rsp); mudar(c.Rbp);
+ while (k < max && c.Rip) {
+ pcs[k++] = c.Rip;
+ DWORD64 img = 0;
+ PRUNTIME_FUNCTION fe = RtlLookupFunctionEntry(c.Rip, &img, nullptr);
+ if (!fe) { // função folha: o retorno está no topo
+ if (!dentro(c.Rsp)) break;
+ c.Rip = *(DWORD64*)c.Rsp; c.Rsp += 8;
+ } else {
+ void* hd = nullptr; DWORD64 ef = 0;
+ RtlVirtualUnwind(UNW_FLAG_NHANDLER, img, c.Rip, fe, &c, &hd, &ef, nullptr);
+ }
+ mudar(c.Rsp); mudar(c.Rbp);
+ if (!dentro(c.Rsp)) break;
+ }
+ } __except (EXCEPTION_EXECUTE_HANDLER) {}
+ return k;
+}
+
+std::wstring Nome(DWORD64 pc) {
+ HMODULE m = nullptr;
+ wchar_t b[MAX_PATH] = L"?";
+ if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (LPCWSTR)pc, &m) && m)
+ GetModuleFileNameW(m, b, MAX_PATH);
+ const wchar_t* s = wcsrchr(b, L'\\');
+ wchar_t o[MAX_PATH + 24];
+ swprintf_s(o, L"%ls+0x%llX", s ? s + 1 : b, m ? (unsigned long long)(pc - (DWORD64)m) : (unsigned long long)pc);
+ return o;
+}
+
+void Vigiar() {
+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
+ HANDLE t = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, FALSE, g_tid);
+ if (!t) { Log(L"sentinela: sem acesso à thread da interface (%lu)", GetLastError()); return; }
+ int registros = 0;
+ for (;;) {
+ Sleep(250);
+ DWORD_PTR r = 0;
+ DWORD t0 = GetTickCount();
+ if (SendMessageTimeoutW(g_alvo, WM_NULL, 0, 0, SMTO_NORMAL, 1000, &r)) continue;
+ if (!IsWindow(g_alvo)) return; // o Shell está saindo
+ if (registros >= 30) { // já registrou bastante: só espera voltar
+ while (!SendMessageTimeoutW(g_alvo, WM_NULL, 0, 0, SMTO_NORMAL, 1000, &r) && IsWindow(g_alvo)) {}
+ continue;
+ }
+ UINT msg = sentinela::ultimaMsg; HWND jan = sentinela::ultimaJanela;
+ DWORD64 pcs[40];
+ int n = Pilha(t, pcs, 40);
+ wchar_t cls[64] = L"?";
+ if (jan) GetClassNameW(jan, cls, 64);
+ std::wstring p;
+ for (int i = 0; i < n; i++) { if (i) p += L" < "; p += Nome(pcs[i]); }
+ registros++;
+ Log(L"sentinela: interface parada há 1 s (mensagem 0x%04X em %ls); pilha: %ls", msg, cls, p.c_str());
+ // espera voltar, para dizer quanto durou (com uma segunda pilha se passar de 4 s: mostra se mudou de lugar)
+ bool segunda = false;
+ while (!SendMessageTimeoutW(g_alvo, WM_NULL, 0, 0, SMTO_NORMAL, 500, &r)) {
+ if (!IsWindow(g_alvo)) return;
+ if (!segunda && GetTickCount() - t0 > 4000) {
+ segunda = true;
+ n = Pilha(t, pcs, 40);
+ p.clear();
+ for (int i = 0; i < n; i++) { if (i) p += L" < "; p += Nome(pcs[i]); }
+ Log(L"sentinela: ainda parada (%lu ms); pilha: %ls", GetTickCount() - t0, p.c_str());
+ }
+ }
+ Log(L"sentinela: a interface voltou depois de %lu ms", GetTickCount() - t0);
+ }
+}
+
+} // namespace
+
+void sentinela::Start(HWND alvo) {
+ g_alvo = alvo;
+ g_tid = GetWindowThreadProcessId(alvo, nullptr);
+ std::thread(Vigiar).detach();
+}
diff --git a/src/shell/shell.h b/src/shell/shell.h
index cc03f2c..8fe3f0f 100644
--- a/src/shell/shell.h
+++ b/src/shell/shell.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
#include <functional>
+#include <atomic>
#include "../comum/idioma.h"
#include <cstdio>
@@ -645,6 +646,16 @@ bool OpenCalculator(const std::wstring& target); // alvo é a Calculadora do Wi
void OpenForceQuit(bool memory); // Forçar Encerrar (Ctrl+Alt+Esc, menu da Apple); memory = "ficou sem memória"
void OpenMonitor(); // Monitor de Atividade (Ctrl+Shift+Esc, menu da Apple) // toca sons\mac\<name>.wav (sons do Mac), sem esperar
void OpenSettings(const std::wstring& page); // abre o Ajustes do Sistema (Ajustes.exe) na página // grava em %APPDATA%\Shell\ajustes.txt
+// ShellExecute numa thread (com o disco ocupado ele segurou a interface 3,2 s; issue #32). Os textos são copiados na hora.
+void Abrir(const wchar_t* verb, const wchar_t* file, const wchar_t* args = nullptr, const wchar_t* dir = nullptr, int show = SW_SHOWNORMAL);
+// roda `f` na thread da interface (pela janela de mensagens): o resultado de um trabalho feito numa thread
+void NaInterface(std::function<void()> f);
+}
+
+namespace sentinela { // sentinela.cpp: registra no shell.log onde a thread da interface ficou parada (1 s ou mais)
+void Start(HWND alvo);
+extern std::atomic<UINT> ultimaMsg; // o laço principal anota a mensagem que vai tratar
+extern std::atomic<HWND> ultimaJanela;
}
namespace ampliar { // animação do "ampliar" do Mac nas janelas de outros apps (ampliar.cpp; pedida pela MacJanela.dll)
diff --git a/src/shell/spotlight.cpp b/src/shell/spotlight.cpp
index 2bd65c7..d8e2560 100644
--- a/src/shell/spotlight.cpp
+++ b/src/shell/spotlight.cpp
@@ -2325,8 +2325,8 @@ void Close(bool restore = false) {
void ShowInFinder(const std::wstring& path) {
for (auto& a : apps::list)
- if (a.finder) { ShellExecuteW(nullptr, L"open", a.launch.c_str(), (L"\"" + path + L"\"").c_str(), nullptr, SW_SHOWNORMAL); return; }
- ShellExecuteW(nullptr, L"open", L"explorer.exe", (L"/select,\"" + path + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
+ if (a.finder) { shell::Abrir(L"open", a.launch.c_str(), (L"\"" + path + L"\"").c_str(), nullptr, SW_SHOWNORMAL); return; }
+ shell::Abrir(L"open", L"explorer.exe", (L"/select,\"" + path + L"\"").c_str(), nullptr, SW_SHOWNORMAL);
}
void Open(int row, bool reveal) {
@@ -2347,7 +2347,7 @@ void Open(int row, bool reveal) {
if (!reveal && r.target.size() > 4 && r.target.find(L":\\") != std::wstring::npos && !_wcsicmp(r.target.c_str() + r.target.size() - 4, L".exe")) {
// nossos apps (e outros pelo .exe): direto
if (!_wcsicmp(r.target.c_str() + r.target.size() - wcslen(EXE_SETTINGS), EXE_SETTINGS)) shell::OpenSettings(L"");
- else ShellExecuteW(nullptr, L"open", r.target.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ else shell::Abrir(L"open", r.target.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
break;
}
if (reveal && r.target.find(L":\\") != std::wstring::npos) { ShowInFinder(r.target); break; } // app com .exe
@@ -2382,12 +2382,12 @@ void Open(int row, bool reveal) {
for (int i = 0; i < n; i++) { wchar_t h[4]; swprintf_s(h, L"%%%02X", (unsigned char)b[i]); u += h; }
}
}
- ShellExecuteW(nullptr, L"open", u.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+ shell::Abrir(L"open", u.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
break;
}
default:
if (reveal) ShowInFinder(r.target);
- else if (!AbrirNoAppMac(r.target)) ShellExecuteW(nullptr, L"open", r.target.c_str(), nullptr, r.detail.c_str(), SW_SHOWNORMAL);
+ else if (!AbrirNoAppMac(r.target)) shell::Abrir(L"open", r.target.c_str(), nullptr, r.detail.c_str(), SW_SHOWNORMAL);
break;
}
Log(L"spotlight: %ls %ls", reveal ? L"mostrando" : L"abrindo", r.name.c_str());
diff --git a/src/shell/ui.cpp b/src/shell/ui.cpp
index 729e57c..a9599ef 100644
--- a/src/shell/ui.cpp
+++ b/src/shell/ui.cpp
@@ -35,6 +35,29 @@ bool ui::Init() {
for (auto f : { L"SF Pro Text", L"Inter", L"Segoe UI Variable Text", L"Segoe UI" }) if (HasFamily(f)) { family = f; break; }
if (!HasFamily(L"Segoe Fluent Icons")) iconFamily = L"Segoe MDL2 Assets";
Log(L"fonte: %ls, ícones: %ls", family.c_str(), iconFamily.c_str());
+ // Fontes carregadas numa thread logo no começo: o DirectWrite abre o arquivo de cada fonte no primeiro texto
+ // desenhado com ela, e com o disco ocupado a 1ª abertura da Estante da Ilha (ícones) parou a interface 2,9 s
+ // (pilha de 22/11/2026 19:55, issue #32). A fábrica é compartilhada: o que esta thread carrega fica no cache.
+ std::thread([fam = family, ic = iconFamily] {
+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);
+ DWORD t0 = GetTickCount();
+ for (const std::wstring& f : { fam, ic, std::wstring(L"SF Pro Display"), std::wstring(L"SF Pro Rounded"), std::wstring(L"Segoe UI") })
+ for (DWRITE_FONT_WEIGHT w : { DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_WEIGHT_MEDIUM, DWRITE_FONT_WEIGHT_SEMI_BOLD, DWRITE_FONT_WEIGHT_BOLD }) {
+ IDWriteTextFormat* tf = nullptr;
+ if (FAILED(dw->CreateTextFormat(f.c_str(), nullptr, w, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 13, L"", &tf)) || !tf) continue;
+ IDWriteTextLayout* tl = nullptr;
+ const wchar_t txt[] = L"Ag 0123 \xE7B8\xE8C8\xE73E\xE7C3";
+ if (SUCCEEDED(dw->CreateTextLayout(txt, (UINT32)wcslen(txt), tf, 400, 40, &tl)) && tl) {
+ DWRITE_TEXT_METRICS m{}; tl->GetMetrics(&m);
+ DWRITE_OVERHANG_METRICS o{}; tl->GetOverhangMetrics(&o);
+ tl->Release();
+ }
+ tf->Release();
+ if (f == ic) break; // ícones: um peso basta
+ }
+ Log(L"fontes: carregadas em %lu ms (fora da interface)", GetTickCount() - t0);
+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);
+ }).detach();
return true;
}
diff --git a/src/shell/widgets.cpp b/src/shell/widgets.cpp
index 4a3b0eb..8d2fcb2 100644
--- a/src/shell/widgets.cpp
+++ b/src/shell/widgets.cpp
@@ -835,7 +835,7 @@ void Click(Widget& wd) {
switch (wd.kind) {
case K_WEATHER: case K_SUN: {
std::wstring app = shell::dir + L"\\" EXE_WEATHER; // como no Mac: o widget abre o app Tempo
- if (GetFileAttributesW(app.c_str()) != INVALID_FILE_ATTRIBUTES) { ShellExecuteW(nullptr, L"open", app.c_str(), nullptr, shell::dir.c_str(), SW_SHOWNORMAL); return; }
+ if (GetFileAttributesW(app.c_str()) != INVALID_FILE_ATTRIBUTES) { shell::Abrir(L"open", app.c_str(), nullptr, shell::dir.c_str(), SW_SHOWNORMAL); return; }
url = L"https://www.google.com/search?q=tempo+" + City();
for (auto& c : url) if (c == L' ') c = L'+';
target = url.c_str(); break;
@@ -843,7 +843,7 @@ void Click(Widget& wd) {
case K_CLOCK: case K_WORLD: target = L"ms-clock:"; break;
case K_CALENDAR: target = L"outlookcal:"; break;
}
- if (target) ShellExecuteW(nullptr, L"open", target, nullptr, nullptr, SW_SHOWNORMAL);
+ if (target) shell::Abrir(L"open", target, nullptr, nullptr, SW_SHOWNORMAL);
}
void Menu(Widget* wd, POINT pt) { // wd nulo: "Editar Widgets…" da mesa (só ligar/desligar e organizar)
@@ -866,7 +866,7 @@ void Menu(Widget* wd, POINT pt) { // wd nulo: "Editar Widgets…" da mesa (só
int id = ctxmenu::ShowItems(g_menuOwner, pt, items);
if (id == 3) {
std::wstring exe = shell::dir + L"\\" EXE_WEATHER;
- ShellExecuteW(nullptr, L"open", exe.c_str(), L"--meu-local", shell::dir.c_str(), SW_SHOWNORMAL);
+ shell::Abrir(L"open", exe.c_str(), L"--meu-local", shell::dir.c_str(), SW_SHOWNORMAL);
} else if (id == 1 && wd) { Show(*wd, false); shell::SetSetting((std::wstring(L"widget.") + wd->id + L".on").c_str(), L"0"); }
else if (id == 2) {
for (auto& w : g_w) w.rc = -1;
diff --git a/src/titulos/main.cpp b/src/titulos/main.cpp
index d21fedb..b880443 100644
--- a/src/titulos/main.cpp
+++ b/src/titulos/main.cpp
@@ -49,6 +49,16 @@ std::wstring shell::Setting(const wchar_t* key, const wchar_t* def) {
void shell::SetSetting(const wchar_t*, const std::wstring&) {}
void atualizacao::Avisar(const std::wstring& title, const std::wstring& body) { Log(L"aviso: %ls — %ls", title.c_str(), body.c_str()); }
+namespace {
+const UINT WM_NA_INTERFACE = WM_APP + 60;
+HWND g_wndUi;
+}
+// como no Shell (main.cpp): o resultado de uma thread volta para a thread das janelas
+void shell::NaInterface(std::function<void()> f) {
+ auto* p = new std::function<void()>(std::move(f));
+ if (!g_wndUi || !PostMessageW(g_wndUi, WM_NA_INTERFACE, 0, (LPARAM)p)) delete p;
+}
+
namespace {
void CALLBACK OnForeground(HWINEVENTHOOK, DWORD, HWND h, LONG obj, LONG, DWORD, DWORD) {
@@ -56,6 +66,7 @@ void CALLBACK OnForeground(HWINEVENTHOOK, DWORD, HWND h, LONG obj, LONG, DWORD,
}
LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
+ if (m == WM_NA_INTERFACE) { auto* p = (std::function<void()>*)l; if (p) { (*p)(); delete p; } return 0; }
if (m == WM_CLOSE) { DestroyWindow(h); return 0; }
if (m == WM_ENDSESSION && w) { janelas::Stop(); return 0; }
if (m == WM_DESTROY) { PostQuitMessage(0); return 0; }
@@ -82,6 +93,7 @@ int WINAPI wWinMain(HINSTANCE hi, HINSTANCE, PWSTR cmd, int) {
// janela comum escondida (não "message-only"): o Shell e o --sair a acham pelo FindWindow
g_wnd = CreateWindowExW(WS_EX_TOOLWINDOW, wc.lpszClassName, L"WacOS Title Bars", WS_POPUP, 0, 0, 0, 0, nullptr, nullptr, hi, nullptr);
if (!g_wnd) return 1;
+ g_wndUi = g_wnd;
if (shell::Setting(L"janelas_mac", L"1") != L"1") Log(L"janelas_mac=0 no ajustes.txt: nada a fazer");
janelas::Start();
SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, nullptr, OnForeground, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);