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

Firefox no longer turns its menu bar on when WacOS brings a window forward; save dialog checks the folder and name before OK (issue #8)

Eternity070628e8a70ef6fbfe
diff --git a/docs/registro-mudancas.txt b/docs/registro-mudancas.txt
index 5fb101b..593408b 100644
--- a/docs/registro-mudancas.txt
+++ b/docs/registro-mudancas.txt
@@ -1304,3 +1304,10 @@ Compilado (tudo), instalado, Shell e reserva do Finder reiniciados às 23:07 sem
- src/shell/genio.cpp: os níveis menores (Half) também vão para a thread; só o nível 0 sobe antes de a janela se mexer. Janela de 3426 px: preparo de 115 ms para 57-78 ms; níveis na tela 30 ms e médias 60 ms depois do começo (log).
- Conferido: o gênio ao ocultar pelo Dock (log) e a sombra de app travado (Electron descartável travado 9 s: Ghost aos 5,5 s, sombra com cloak=1; voltou, cloak=0).
DESFAZER: reverter o commit.
+
+[2026-11-23 01:25, hora do PC] Issue #8 (carlosjrrr, 23/11): Firefox com a barra de menus ligada sozinha e salvar no ScreenRec indo para a pasta de cima.
+ - src/shell/shell.h: shell::LiberaFrente() = Alt com uma tecla sem função (vkE8) no meio, marcadas como nossas. Alt sozinho, ao soltar, liga a barra Arquivo/Editar/Exibir do Firefox (igual ao F10).
+ - src/shell/apps.cpp, dock.cpp, genio.cpp, revelar.cpp, main.cpp, missioncontrol.cpp, progresso.cpp e src/ajustes/main.cpp: o truque do Alt para trazer janelas para a frente passou a usar isso.
+ - src/shell/dialogs.cpp: a original só conta como "já na pasta escolhida" quando a barra de endereço traz o caminho (pelo nome de pasta especial pode ser outra de mesmo nome); nesse caso recebe só o nome. Antes do OK confere de novo a pasta (se saiu, vai o caminho inteiro) e, se o nome não entrou no campo, procura o campo de novo e tenta outra vez. Log com a pasta da original e a escolhida.
+ ScreenRec não reproduzido aqui (app não instalado); pedido o log ao usuário.
+ DESFAZER: reverter o commit.
diff --git a/src/ajustes/main.cpp b/src/ajustes/main.cpp
index 558d1ae..79a2bb1 100644
--- a/src/ajustes/main.cpp
+++ b/src/ajustes/main.cpp
@@ -19,6 +19,12 @@
#include "../comum/semaforo.h"
#include "../comum/leopard.h" // tema Mac OS X Leopard: barra metálica de ponta a ponta
+// Libera o SetForegroundWindow (a última entrada foi nossa). Alt com uma tecla sem função (vkE8) no meio: Alt sozinho,
+// ao soltar, ligava a barra de menus do app da frente (Firefox, issue #8).
+static void LiberaFrente() {
+ keybd_event(VK_MENU, 0, 0, 0); keybd_event(0xE8, 0, 0, 0); keybd_event(0xE8, 0, KEYEVENTF_KEYUP, 0); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
+}
+
namespace {
// ---- Medidas (pt), tiradas da referência
@@ -2106,7 +2112,7 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
if (w == T_SLIDE) { FlushSlide(); return 0; }
if (w == T_FRENTE) { // já à mostra (o Shell terminou a animação de abrir): para a frente de verdade
KillTimer(h, T_FRENTE);
- if (GetForegroundWindow() != h) { keybd_event(VK_MENU, 0, 0, 0); SetForegroundWindow(h); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); }
+ if (GetForegroundWindow() != h) { LiberaFrente(); SetForegroundWindow(h); }
BringWindowToTop(h);
return 0;
}
@@ -2190,7 +2196,7 @@ LRESULT CALLBACK WndProc(HWND h, UINT m, WPARAM w, LPARAM l) {
else if (id == L"atualizacao") { int g = SidebarIndexFor(L"geral"); if (g >= 0) SelectSide(g); OpenUpdatePage(); }
}
if (IsIconic(h)) ShowWindow(h, SW_RESTORE);
- keybd_event(VK_MENU, 0, 0, 0); SetForegroundWindow(h); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0); // já aberta: para a frente mesmo atrás de outro app
+ LiberaFrente(); SetForegroundWindow(h); // já aberta: para a frente mesmo atrás de outro app
BringWindowToTop(h);
return TRUE;
}
diff --git a/src/shell/apps.cpp b/src/shell/apps.cpp
index 68af7c3..beb157e 100644
--- a/src/shell/apps.cpp
+++ b/src/shell/apps.cpp
@@ -1036,9 +1036,8 @@ static void LaunchNow(App a, const std::wstring& args) {
static void ForceForeground(HWND h) {
if (SetForegroundWindow(h)) return;
// o clique foi para o nosso processo, então costuma funcionar; senão, o truque do Alt
- keybd_event(VK_MENU, 0, 0, 0);
+ shell::LiberaFrente();
SetForegroundWindow(h);
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
}
// Ocultar: por baixo é minimizar (o Windows não deixa esconder janela de outro programa com segurança),
diff --git a/src/shell/dialogs.cpp b/src/shell/dialogs.cpp
index 0e37299..d786119 100644
--- a/src/shell/dialogs.cpp
+++ b/src/shell/dialogs.cpp
@@ -238,7 +238,9 @@ std::wstring KnownFolderByName(const std::wstring& name) {
}
// Pasta onde a janela original está: a barra de endereço tem o texto "Endereço: C:\..." / "Address: ...".
-std::wstring CurrentFolder(HWND dlg) {
+// porNome: a barra só trazia o nome (pasta especial) e o caminho veio de KnownFolderByName, que pode errar quando
+// duas pastas têm o mesmo nome ("Vídeos" do usuário e uma "Videos" dentro de Imagens do OneDrive).
+std::wstring CurrentFolder(HWND dlg, bool* porNome = nullptr) {
struct C { std::wstring found, name; } c;
EnumChildWindows(dlg, [](HWND w, LPARAM p) -> BOOL {
wchar_t cls[32]; GetClassNameW(w, cls, 32);
@@ -256,6 +258,7 @@ std::wstring CurrentFolder(HWND dlg) {
std::wstring n = c.name;
if (size_t s = n.find_last_of(L'\\'); s != std::wstring::npos) n = n.substr(s + 1); // "Bibliotecas\Documentos"
c.found = KnownFolderByName(n);
+ if (porNome) *porNome = true;
}
return c.found;
}
@@ -344,7 +347,15 @@ void Finish(const Request& r, const std::vector<std::wstring>& paths, int type)
size_t cut = paths[0].find_last_of(L'\\');
std::wstring dir = cut == std::wstring::npos ? L"" : paths[0].substr(0, cut);
if (dir.size() == 2) dir += L'\\';
- if (!dir.empty() && !SameFolder(CurrentFolder(r.dlg), dir)) {
+ // Já "na" pasta escolhida só vale com o caminho lido na barra: pelo nome (pasta especial) pode ser outra de
+ // mesmo nome, e aí o arquivo ia para a pasta errada com o nome errado (ScreenRec: salvava uma pasta acima,
+ // com o nome original; issue #8, 23/11/2026). Entrar de novo na mesma pasta não faz mal.
+ bool porNome = false;
+ std::wstring atual = CurrentFolder(r.dlg, &porNome);
+ bool jaNela = !porNome && SameFolder(atual, dir);
+ Log(L" original em '%ls'%ls; escolhida '%ls'", atual.c_str(), porNome ? L" (pelo nome)" : L"", dir.c_str());
+ if (jaNela) value = PathFindFileNameW(paths[0].c_str());
+ if (!dir.empty() && !jaNela) {
PoeTexto(r.dlg, edit, dir);
SendMessageTimeoutW(r.dlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem(r.dlg, IDOK), SMTO_NORMAL, 10000, nullptr);
bool entrou = false;
@@ -358,7 +369,21 @@ void Finish(const Request& r, const std::vector<std::wstring>& paths, int type)
// a janela pode refazer o campo do nome ao trocar de pasta: o de antes já não vale
Responde(r.dlg, 10000);
if (HWND e2 = NameEdit(r.dlg); e2 && e2 != edit && r.mode != 2) { Log(L" o campo do nome mudou ao trocar de pasta"); edit = e2; }
- if (!PoeTexto(r.dlg, edit, value)) Log(L" o campo do nome não ficou com o escolhido ('%ls')", Text(edit).c_str());
+ // Só o nome: confere de novo que a original continua na pasta escolhida (o programa pode trocar a pasta ao mudar o
+ // tipo ou ao recriar o campo). Se saiu, vai o caminho inteiro.
+ if (r.mode == 1 && paths.size() == 1 && value.find(L'\\') == std::wstring::npos) {
+ std::wstring dir = paths[0].substr(0, paths[0].find_last_of(L'\\'));
+ if (dir.size() == 2) dir += L'\\';
+ std::wstring atual = CurrentFolder(r.dlg);
+ if (!SameFolder(atual, dir)) { Log(L" a original saiu da pasta escolhida ('%ls'): vai o caminho inteiro", atual.c_str()); value = paths[0]; }
+ }
+ bool nomeOk = PoeTexto(r.dlg, edit, value);
+ if (!nomeOk) { // o campo pode ter sido refeito: procura de novo e tenta mais uma vez
+ Responde(r.dlg, 5000);
+ if (HWND e3 = r.mode != 2 ? NameEdit(r.dlg) : nullptr; e3) edit = e3;
+ nomeOk = PoeTexto(r.dlg, edit, value);
+ }
+ if (!nomeOk) Log(L" o campo do nome não ficou com o escolhido ('%ls')", Text(edit).c_str());
PostMessageW(r.dlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem(r.dlg, IDOK));
// A original (fora da tela) pode abrir uma pergunta depois do OK: "já existe, substituir?" ou um aviso de nome
// inválido, que nascia fora da tela junto: o programa ficava travado até alguém apertar Esc (Firefox, issue #8,
diff --git a/src/shell/dock.cpp b/src/shell/dock.cpp
index e214e73..260baf6 100644
--- a/src/shell/dock.cpp
+++ b/src/shell/dock.cpp
@@ -1500,7 +1500,7 @@ void LeftClick(int i) {
RECT from = ToScreenRect({ it.cx - s / 2, top, it.cx + s / 2, top + s });
if (genio::Restore(h, from)) { apps::Refresh(); BuildItems(); Paint(); return; }
shell::Restaurar(h);
- keybd_event(VK_MENU, 0, 0, 0); SetForegroundWindow(h); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
+ shell::LiberaFrente(); SetForegroundWindow(h);
apps::Refresh(); BuildItems(); Paint();
return;
}
diff --git a/src/shell/genio.cpp b/src/shell/genio.cpp
index 7fb541e..2f399c1 100644
--- a/src/shell/genio.cpp
+++ b/src/shell/genio.cpp
@@ -56,7 +56,7 @@ void RealBack() {
if (g_a.realBack || !IsWindow(g_a.target)) return;
g_a.realBack = true;
shell::Restaurar(g_a.target);
- keybd_event(VK_MENU, 0, 0, 0); SetForegroundWindow(g_a.target); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
+ shell::LiberaFrente(); SetForegroundWindow(g_a.target);
SetWindowPos(g_ov, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // a camada continua por cima
dock::Raise();
}
diff --git a/src/shell/main.cpp b/src/shell/main.cpp
index effc71c..b258e12 100644
--- a/src/shell/main.cpp
+++ b/src/shell/main.cpp
@@ -1017,8 +1017,7 @@ static LRESULT CALLBACK MsgProc(HWND h, UINT m, WPARAM w, LPARAM l) {
}
case WM_APP_MISSION:
if (launchpad::IsOpen()) launchpad::Toggle();
- keybd_event(VK_MENU, 0, 0, KEY_MARK); // permite ao Mission Control vir para a frente
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente(); // permite ao Mission Control vir para a frente
missioncontrol::Toggle();
return 0;
case WM_APP_EXPOSE: {
@@ -1028,8 +1027,7 @@ static LRESULT CALLBACK MsgProc(HWND h, UINT m, WPARAM w, LPARAM l) {
App* a = root && !apps::IsShellWindow(root) ? apps::OfWindow(root) : nullptr;
if (!a) { Log(L"Exposé do app: a janela da frente não é de um app do Dock"); return 0; }
if (launchpad::IsOpen()) launchpad::Toggle();
- keybd_event(VK_MENU, 0, 0, KEY_MARK); // permite ao Exposé vir para a frente
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente(); // permite ao Exposé vir para a frente
missioncontrol::ToggleApp(a->id, a->name);
return 0;
}
@@ -1068,13 +1066,11 @@ static LRESULT CALLBACK MsgProc(HWND h, UINT m, WPARAM w, LPARAM l) {
case WM_APP_SWITCH_END: seletor::Release(); return 0;
case WM_APP_SPOTLIGHT:
if (launchpad::IsOpen()) launchpad::Toggle();
- keybd_event(VK_MENU, 0, 0, KEY_MARK); // permite ao Spotlight vir para a frente e receber o teclado
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente(); // permite ao Spotlight vir para a frente e receber o teclado
spotlight::Toggle();
return 0;
case WM_APP_LAUNCHPAD:
- keybd_event(VK_MENU, 0, 0, KEY_MARK); // permite ao Launchpad vir para a frente
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente(); // permite ao Launchpad vir para a frente
launchpad::Toggle();
return 0;
case WM_APP_WINKEY: mesa::WinKey((UINT)w); return 0;
@@ -1082,7 +1078,7 @@ static LRESULT CALLBACK MsgProc(HWND h, UINT m, WPARAM w, LPARAM l) {
case WM_APP_VOLUME: som::Key((UINT)w, l != 0); return 0;
case WM_SYSCOMMAND:
if ((w & 0xFFF0) == SC_TASKLIST) { // Ctrl+Esc com o Shell como Taskman (sem Explorador): Launchpad
- keybd_event(VK_MENU, 0, 0, KEY_MARK); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente();
launchpad::Toggle();
return 0;
}
diff --git a/src/shell/missioncontrol.cpp b/src/shell/missioncontrol.cpp
index 3d52318..72c738a 100644
--- a/src/shell/missioncontrol.cpp
+++ b/src/shell/missioncontrol.cpp
@@ -756,8 +756,7 @@ void Finish() {
g_xFor = nullptr; g_xHot = false;
if (g_cd && g_cwins) { g_cwins->RemoveAllVisuals(); g_wallFx->SetOpacity(1.f); g_barFx->SetOpacity(1.f); g_cd->Commit(); }
if (g_pick) {
- keybd_event(VK_MENU, 0, 0, KEY_MARK); // permite trazer a janela para a frente
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
+ shell::LiberaFrente(); // permite trazer a janela para a frente
SetForegroundWindow(g_pick);
g_pick = nullptr;
}
diff --git a/src/shell/progresso.cpp b/src/shell/progresso.cpp
index c7daefa..5d3a10a 100644
--- a/src/shell/progresso.cpp
+++ b/src/shell/progresso.cpp
@@ -250,10 +250,8 @@ void FocusAway(HWND h) {
static std::map<HWND, DWORD> tried; // o truque do Alt (o mesmo do Dock), no máximo a cada 2 s por janela
if (!ok && GetTickCount() - tried[h] > 2000) {
tried[h] = GetTickCount();
- const ULONG_PTR KEY_MARK = 0x53484C4C; // tecla injetada por nós (o gancho do teclado do Shell ignora)
- keybd_event(VK_MENU, 0, 0, KEY_MARK);
+ shell::LiberaFrente();
ok = SetForegroundWindow(to);
- keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, KEY_MARK);
Log(L"progresso: foco de volta para %p pelo Alt (%ls)", to, ok ? L"ok" : L"falhou");
}
}
diff --git a/src/shell/revelar.cpp b/src/shell/revelar.cpp
index 5fd9945..d675611 100644
--- a/src/shell/revelar.cpp
+++ b/src/shell/revelar.cpp
@@ -357,7 +357,7 @@ void Step() {
if (back) {
g_revealed = false;
if (!g_moved.empty() && IsWindow(g_moved.front().h)) { // a que estava na frente volta a ter o foco
- keybd_event(VK_MENU, 0, 0, 0); SetForegroundWindow(g_moved.front().h); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0);
+ shell::LiberaFrente(); SetForegroundWindow(g_moved.front().h);
}
g_moved.clear();
}
diff --git a/src/shell/shell.h b/src/shell/shell.h
index b6a288e..feb6fce 100644
--- a/src/shell/shell.h
+++ b/src/shell/shell.h
@@ -628,6 +628,14 @@ bool SoDock();
// Tira a janela de minimizada. Numa janela de administrador o ShowWindow de fora e recusado pelo Windows (o explorer
// nao e administrador); o pedido pelo menu de sistema dela (WM_SYSCOMMAND) passa.
inline void Restaurar(HWND h) { ShowWindow(h, SW_RESTORE); if (IsIconic(h)) PostMessageW(h, WM_SYSCOMMAND, SC_RESTORE, 0); }
+// Libera o SetForegroundWindow: o processo que mandou a última entrada pode trocar a janela da frente. Era só Alt
+// apertado e solto, mas Alt sozinho, ao soltar, liga a barra de menus do app da frente (o Firefox abria com a barra
+// Arquivo/Editar/Exibir à mostra, igual ao F10; issue #8). Uma tecla sem função (vkE8) no meio desfaz isso. Marcadas
+// como nossas: o gancho do teclado do Shell deixa passar.
+inline void LiberaFrente() {
+ const ULONG_PTR M = 0x53484C4C;
+ keybd_event(VK_MENU, 0, 0, M); keybd_event(0xE8, 0, 0, M); keybd_event(0xE8, 0, KEYEVENTF_KEYUP, M); keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, M);
+}
int RodarNativo(HINSTANCE dll, const std::wstring& dirBin, const std::wstring& logPath);
// abre o Finder com estes argumentos: no nativo, no Finder de dentro do explorer (MacFinder.dll); senão o WacOSFinder.exe
void AbrirFinder(const std::wstring& args);