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

Issues after build-57: Explorer wait off the UI thread (#199), tray pins by program (#237), Settings remembers its size (#236), Multicolor accent (#240), exit code in the watchdog log (#233)

Eternity0706284b610ab4a60b
diff --git a/docs/registro-mudancas.txt b/docs/registro-mudancas.txt
index c00a7e0..8bfcea5 100644
--- a/docs/registro-mudancas.txt
+++ b/docs/registro-mudancas.txt
@@ -2098,3 +2098,16 @@ Compilado (tudo), instalado, Shell e reserva do Finder reiniciados às 23:07 sem
Shell abre como shell já roda (abriam duas vezes).
Compilado (build.cmd e build.cmd janelas). Não instalado.
DESFAZER: reverter o commit e compilar (build.cmd e build.cmd janelas).
+[2026-11-28 16:10] Issues novos depois da build-57 (C++ e Rust):
+ - #199 (interface parada): no login com o Shell registrado, StartExplorer esperava até 16,5 s pela mesa do Explorador
+ na thread da interface (a sentinela do log do usuário pegou 16453 ms). Chamado pelo Tick agora espera numa
+ thread (mesa.cpp / mesa.rs); ao sair e no vigia continua esperando (o processo pode acabar antes).
+ - #237: ícone fixado na barra de menus guardado como "@programa" (+ "#{GUID}" se tiver) em vez da dica; apps que
+ trocam a dica (Vikey) não voltam mais para a setinha. As chaves antigas (dica) continuam valendo (menubar).
+ - #236: Ajustes do Sistema lembra posição e tamanho (%APPDATA%\Shell\ajustes-janela.txt, fora do ajustes.txt).
+ - #240: clicar em Multicor gravava "azul" (a bolinha pulava para o azul); agora grava "multicor" (a cor continua azul).
+ - #233: o vigia registra o código de saída quando o Shell some sem sair direito.
+ - #238 (só Rust): a edição em Rust não tem tools\, então a Atualização de Software ficava "desconhecida"/"não deu
+ para conferir". Confere e atualiza pela instalação normal (Programs\WacOS, WacOSSetup --atualizar).
+ Compilado (build.cmd shell, build.cmd ajustes; build-rust.ps1 -Zip). Não instalado.
+ DESFAZER: reverter os commits (main e claude/rust-port-teste-23da8b) e compilar de novo.
diff --git a/src/ajustes/main.cpp b/src/ajustes/main.cpp
index ca24415..16eb1c2 100644
--- a/src/ajustes/main.cpp
+++ b/src/ajustes/main.cpp
@@ -2054,6 +2054,40 @@ void LigaRelogio(HWND h) {
}
bool PedidoRenomear(const std::wstring& id); // Renomear… do Dock e do Launchpad (mais abaixo)
+// Posição e tamanho da janela entre uma abertura e outra (issue #236): %APPDATA%\Shell\ajustes-janela.txt com
+// "x y largura altura" em px. Fora do ajustes.txt de propósito: o Shell relê tudo a cada gravação dele.
+static std::wstring JanelaArq() {
+ wchar_t ad[MAX_PATH] = {};
+ if (!GetEnvironmentVariableW(L"APPDATA", ad, MAX_PATH)) return L"";
+ return std::wstring(ad) + L"\\Shell\\ajustes-janela.txt";
+}
+static void GuardaJanela(HWND h) {
+ if (!h || IsZoomed(h) || IsIconic(h) || !IsWindowVisible(h)) return;
+ RECT r; if (!GetWindowRect(h, &r)) return;
+ std::wstring f = JanelaArq(); if (f.empty()) return;
+ FILE* fp = nullptr;
+ if (_wfopen_s(&fp, f.c_str(), L"w") || !fp) return;
+ fwprintf(fp, L"%ld %ld %ld %ld\n", r.left, r.top, r.right - r.left, r.bottom - r.top);
+ fclose(fp);
+}
+// a guardada, se ainda cabe num monitor (o monitor pode ter saído) e não é menor que o mínimo
+static bool LeJanela(int& x, int& y, int& w, int& hh, float scale) {
+ std::wstring f = JanelaArq(); if (f.empty()) return false;
+ FILE* fp = nullptr;
+ if (_wfopen_s(&fp, f.c_str(), L"r") || !fp) return false;
+ int a = 0, b = 0, c = 0, d = 0;
+ int n = fwscanf_s(fp, L"%d %d %d %d", &a, &b, &c, &d);
+ fclose(fp);
+ if (n != 4 || c < (int)(680 * scale) || d < (int)(420 * scale)) return false;
+ RECT r{ a, b, a + c, b + d }, inter;
+ HMONITOR mon = MonitorFromRect(&r, MONITOR_DEFAULTTONULL);
+ MONITORINFO mi{ sizeof(mi) };
+ if (!mon || !GetMonitorInfoW(mon, &mi) || !IntersectRect(&inter, &r, &mi.rcWork)) return false;
+ if (inter.right - inter.left < 200 || inter.bottom - inter.top < 100) return false; // quase toda fora da tela
+ x = a; y = std::max<int>(b, mi.rcWork.top); w = std::min<int>(c, mi.rcWork.right - mi.rcWork.left); hh = std::min<int>(d, mi.rcWork.bottom - mi.rcWork.top);
+ return true;
+}
+
LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
if (m == WM_QUADRO) {
g_quadroPendente = false;
@@ -2300,7 +2334,8 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
Invalidate();
return 0;
}
- case WM_CLOSE: DestroyWindow(h); return 0;
+ case WM_EXITSIZEMOVE: GuardaJanela(h); break;
+ case WM_CLOSE: GuardaJanela(h); DestroyWindow(h); return 0;
case WM_DESTROY: shadow::Destroy(); PostQuitMessage(0); return 0;
}
return DefWindowProcW(h, m, w, l);
@@ -2447,6 +2482,7 @@ int WINAPI wWinMain(HINSTANCE hi, HINSTANCE, LPWSTR, int) {
const bool th0 = tahoe::On(), gg0 = th0 && tahoe::Golden(); // Tahoe: 801 × 625 (guia, seção 43); macOS 27: 740 × 690 (captura)
int ww = (int)((gg0 ? 740 : th0 ? 801 : 715) * g_scale), wh = (int)(std::min(gg0 ? 690.f : th0 ? 625.f : 640.f, (wa.bottom - wa.top) / g_scale - 60) * g_scale);
int wx = wa.left + (wa.right - wa.left - ww) / 2, wy = wa.top + (wa.bottom - wa.top - wh) / 2 - (int)(20 * g_scale);
+ if (LeJanela(wx, wy, ww, wh, g_scale)) wa.top = std::min<LONG>(wa.top, wy); // como estava ao fechar (issue #236)
g_hwnd = CreateWindowExW(WS_EX_NOREDIRECTIONBITMAP, wc.lpszClassName, TrPick(L"Ajustes do Sistema", L"System Settings"), WS_OVERLAPPEDWINDOW,
wx, std::max<int>(wy, wa.top), ww, wh, nullptr, nullptr, hi, nullptr);
ampliacao::Janela(g_hwnd); // abrir e fechar animados (o Shell anima)
diff --git a/src/ajustes/paginas.cpp b/src/ajustes/paginas.cpp
index f6db0fb..426c475 100644
--- a/src/ajustes/paginas.cpp
+++ b/src/ajustes/paginas.cpp
@@ -916,7 +916,7 @@ Page Aparencia() {
acc.clickAt = [](D2D1_POINT_2F pt, D2D1_RECT_F rr) {
float x = rr.right - 10 - 9 * 22 + 8;
for (int k = 0; k < 9; k++, x += 22)
- if (std::fabs(pt.x - x) <= 10 && std::fabs(pt.y - (rr.top + 19)) <= 10) { SetSetting(L"destaque", k == 0 ? L"azul" : ACCENTS[k].first); Rebuild(); }
+ if (std::fabs(pt.x - x) <= 10 && std::fabs(pt.y - (rr.top + 19)) <= 10) { SetSetting(L"destaque", ACCENTS[k].first); /* multicor fica multicor (issue #240); a cor é o azul */ Rebuild(); }
};
Row tema = TemaRow();
// o Tema fica sempre livre: com "Reduzir transparência" o vidro só fica opaco (como no Mac)
@@ -1232,7 +1232,7 @@ Page AparenciaGolden() {
color.clickAt = [](D2D1_POINT_2F pt, D2D1_RECT_F rr) {
for (int k = 0; k < 10; k++) {
float x = rr.right - 21.75f - (9 - k) * 36.f;
- if (std::fabs(pt.x - x) <= 15 && std::fabs(pt.y - (rr.top + 21.25f)) <= 15) { SetSetting(L"destaque", k == 0 ? L"azul" : GG_KEYS[k]); Rebuild(); }
+ if (std::fabs(pt.x - x) <= 15 && std::fabs(pt.y - (rr.top + 21.25f)) <= 15) { SetSetting(L"destaque", GG_KEYS[k]); /* multicor fica multicor (issue #240) */ Rebuild(); }
}
};
Row hl = Popup(L"Cor do realce do texto", { L"Automática", L"Azul", L"Roxo", L"Rosa", L"Vermelho", L"Laranja", L"Amarelo", L"Verde", L"Grafite" },
diff --git a/src/shell/menubar.cpp b/src/shell/menubar.cpp
index cfc8162..1bc1b6c 100644
--- a/src/shell/menubar.cpp
+++ b/src/shell/menubar.cpp
@@ -119,17 +119,31 @@ std::wstring TrayKey(const TrayIcon& t) { // nome estável: a dica até a prime
while (!k.empty() && k.back() == L' ') k.pop_back();
return k.empty() ? ProgramaDoIcone(t.hwnd) : k;
}
+// A chave que se guarda desde o issue #237: "@programa" (mais "#{GUID}" quando o ícone tem GUID). Apps que trocam a dica
+// enquanto rodam (Vikey: "Vikey", "Vikey – Tiếng Việt", "Vikey – English") voltavam para a setinha a cada troca, porque a
+// chave era a dica. O uid fica de fora: alguns apps sorteiam um a cada vez que abrem (MSI Afterburner). As chaves antigas
+// (a dica) continuam valendo até o ícone ser fixado de novo.
+std::wstring TrayId(const TrayIcon& t) {
+ std::wstring p = ProgramaDoIcone(t.hwnd);
+ if (p.empty()) return L"";
+ static const GUID zero{};
+ if (memcmp(&t.guid, &zero, sizeof(GUID))) {
+ wchar_t g[64] = {};
+ if (StringFromGUID2(t.guid, g, 64)) return L"@" + p + L"#" + g;
+ }
+ return L"@" + p;
+}
bool IsShown(const TrayIcon& t) {
if (shell::Setting(L"barra_icones_todos", L"0") == L"1") return true; // Central de Controle: "Sempre na barra de menus"
- std::wstring k = TrayKey(t);
- for (auto& s : Shown()) if (!_wcsicmp(s.c_str(), k.c_str())) return true;
+ std::wstring k = TrayKey(t), id = TrayId(t);
+ for (auto& s : Shown()) if (!_wcsicmp(s.c_str(), k.c_str()) || (!id.empty() && !_wcsicmp(s.c_str(), id.c_str()))) return true;
return false;
}
void SetShown(const TrayIcon& t, bool on) {
auto v = Shown();
- std::wstring k = TrayKey(t);
- v.erase(std::remove_if(v.begin(), v.end(), [&](const std::wstring& x) { return !_wcsicmp(x.c_str(), k.c_str()); }), v.end());
- if (on) v.push_back(k);
+ std::wstring k = TrayKey(t), id = TrayId(t);
+ v.erase(std::remove_if(v.begin(), v.end(), [&](const std::wstring& x) { return !_wcsicmp(x.c_str(), k.c_str()) || (!id.empty() && !_wcsicmp(x.c_str(), id.c_str())); }), v.end());
+ if (on) v.push_back(id.empty() ? k : id);
std::wstring out;
for (auto& x : v) { if (!out.empty()) out += L"|"; out += x; }
shell::SetSetting(L"barra_icones", out);
diff --git a/src/shell/mesa.cpp b/src/shell/mesa.cpp
index 31a7a60..7c953ba 100644
--- a/src/shell/mesa.cpp
+++ b/src/shell/mesa.cpp
@@ -17,7 +17,7 @@
// da mesa ou para outra casa da grade), soltar arquivos de fora, F2 renomeia, Delete vai para a Lixeira,
// Ctrl+C/X/V, menu de contexto (o nosso, com as extensões do Windows) e o menu do fundo do Mac.
#include "shell.h"
-#include "../comum/fonte_cjk.h" // a reserva para coreano, japonês e chinês
+#include "../comum/fonte_cjk.h" // a reserva para coreano, japonês e chinês
#include "../comum/ajustes_arquivo.h"
#include <dwmapi.h>
#include "../menu/context_menu.h"
@@ -273,8 +273,14 @@ void CloseGhostExplorers(double minAge, const wchar_t* why) {
}
}
-void StartExplorer(const wchar_t* why) {
+// fundo = chamado pelo Tick da thread da interface: a espera pela mesa do Explorador (até 16,5 s) vai para outra thread.
+// Antes ela ficava na thread da interface e, no login com o Shell registrado, o WacOS ficava parado 16 s inteiros quando
+// o Explorador demorava (issue #199: a sentinela pegou 16453 ms nesse Sleep). Ao sair (e no vigia) continua esperando:
+// o processo pode acabar antes de uma thread devolver o valor do Winlogon.
+std::atomic<bool> g_trocandoShell;
+void StartExplorer(const wchar_t* why, bool fundo = false) {
if (ExplorerProgman()) return;
+ if (g_trocandoShell) return; // outra abertura ainda está esperando a mesa dele
CloseGhostExplorers(0, L"antes de abrir o Explorador"); // senão o Explorador novo trava
// Com o WacOSShell como shell do Windows, o explorer.exe se abre só como janela de pasta. Por alguns
// segundos o valor volta a ser explorer.exe (ele confere ao abrir) e depois é devolvido.
@@ -293,10 +299,16 @@ void StartExplorer(const wchar_t* why) {
Log(L"mesa: Explorador aberto de novo (%ls)", why);
} else Log(L"mesa: ERRO abrindo o Explorador (%lu)", GetLastError());
if (swap) {
- for (int i = 0; i < 60 && !ExplorerProgman(); i++) Sleep(250); // até 15 s pela mesa dele
- Sleep(1500);
- RegSetKeyValueW(HKEY_CURRENT_USER, WINLOGON, L"Shell", REG_SZ, saved.c_str(), (DWORD)(saved.size() + 1) * 2);
- Log(L"mesa: Winlogon Shell devolvido (%ls); Explorador %ls", saved.c_str(), ExplorerProgman() ? L"é a mesa" : L"NÃO virou a mesa");
+ auto espera = [saved] {
+ for (int i = 0; i < 60 && !ExplorerProgman(); i++) Sleep(250); // até 15 s pela mesa dele
+ Sleep(1500);
+ RegSetKeyValueW(HKEY_CURRENT_USER, WINLOGON, L"Shell", REG_SZ, saved.c_str(), (DWORD)(saved.size() + 1) * 2);
+ Log(L"mesa: Winlogon Shell devolvido (%ls); Explorador %ls", saved.c_str(), ExplorerProgman() ? L"é a mesa" : L"NÃO virou a mesa");
+ g_trocandoShell = false;
+ };
+ g_trocandoShell = true;
+ if (fundo) std::thread(espera).detach();
+ else espera();
}
}
@@ -1714,8 +1726,8 @@ void Tick() {
if (shell::SoDock()) opt = L"1"; // só Dock e barra de menus: a área de trabalho e os ícones são os do Windows
bool registered = WinlogonIsOurs();
bool want0 = opt == L"0";
- // sem o ajuste: fundo (o padrão do instalador). Antes, vazio e sem o registro do Winlogon = a mesa do Explorador, e quem
- // perdeu a linha do ajustes.txt ficava com os ícones e o menu de clique direito do Windows (23/11/2026)
+ // sem o ajuste: fundo (o padrão do instalador). Antes, vazio e sem o registro do Winlogon = a mesa do Explorador, e quem
+ // perdeu a linha do ajustes.txt ficava com os ícones e o menu de clique direito do Windows (23/11/2026)
g_fundo = opt == L"fundo" || opt.empty();
// nativo: o Shell roda dentro do explorer.exe; a mesa do projeto fica por cima da dele (os ícones e o papel
// de parede do Windows ficam atrás, sem uso) e nunca se pede para o Explorador sair
@@ -1813,7 +1825,7 @@ void Tick() {
if (g_standalone) { // estava sem o Explorador e o ajuste voltou para 1: devolve a mesa a ele
LeaveShell();
DestroyDesk();
- StartExplorer(L"ajuste explorer=1");
+ StartExplorer(L"ajuste explorer=1", true);
g_weClosed = false;
return;
}
@@ -1824,7 +1836,7 @@ void Tick() {
if ((registered || g_fundo || shell::SoDock()) && now - g_explorerGoneAt > 2000 && (!lastStart || now - lastStart > 30000)) { // só Dock: a área de trabalho é a dele
lastStart = now;
if (DeskExists()) DestroyDesk();
- StartExplorer(L"explorer=1 com o Shell registrado");
+ StartExplorer(L"explorer=1 com o Shell registrado", true);
return;
}
if (!DeskExists() && now - g_explorerGoneAt > 3000) { Log(L"mesa: Explorador ausente; mostrando a mesa do Shell"); CreateDesk(); }
@@ -2292,7 +2304,12 @@ bool mesa::Watchdog(const wchar_t* cmdLine) {
// de cursores é relido do registro
if (WaitForSingleObject(ev, 0) != WAIT_OBJECT_0) SystemParametersInfoW(SPI_SETCURSORS, 0, nullptr, 0);
if (!done && r == WAIT_OBJECT_0 + 1 && WaitForSingleObject(ev, 0) != WAIT_OBJECT_0) {
- vlog(L"o Shell sumiu sem sair direito");
+ // o código de saída diz o porquê (issue #233, nada no log nem no Visualizador de Eventos): 0xC0000409 = falha
+ // rápida (estouro de buffer, std::terminate), 0xC0000374 = heap corrompida, 0xC00000FD = pilha cheia, 3 = abort,
+ // 1 ou outro número pequeno = encerrado por outro programa (TerminateProcess)
+ DWORD codigo = 0;
+ if (GetExitCodeProcess(proc, &codigo)) { wchar_t m[96]; swprintf_s(m, L"o Shell sumiu sem sair direito (código de saída 0x%08lX)", codigo); vlog(m); }
+ else vlog(L"o Shell sumiu sem sair direito");
// fechado à força (Gerenciador de Tarefas) com o Explorador no fundo: a barra dele ficava escondida e o
// usuário ficava sem barra de tarefas nenhuma (issue #37)
EnumWindows([](HWND h, LPARAM) -> BOOL {