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

No disk, Registry or process waits on app and Shell window threads; animation frames no longer queue ahead of input

Eternity0706286eb6437a475a
diff --git a/docs/registro-mudancas.txt b/docs/registro-mudancas.txt
index b463fdd..ee11bde 100644
--- a/docs/registro-mudancas.txt
+++ b/docs/registro-mudancas.txt
@@ -1210,3 +1210,10 @@ Compilado (tudo), instalado, Shell e reserva do Finder reiniciados às 23:07 sem
- Cantos: as capas que imitavam o canto do Finder saíram (escolha do usuário: 8 px do Windows sem recorte). Teste num Electron descartável, sete fases (parado, cor de trás mudando, foco, arraste, soltar): 0 pixels com cor velha.
- Engasgo: as capas liam a tela 4 vezes (~23 ms) na thread do app a cada passo. Releitura da cor 33 -> 100 ms, foto da faixa 120 -> 250 ms. Medido no Electron de teste, antes -> depois (sem a barra): mover 22,2 -> 0,8 ms (0,4); redimensionar 54,4 -> 9,0 (1,3); pior troca de foco 98,8 -> 24,2 (1,8).
DESFAZER: reverter o commit.
+
+[2026-11-22 17:50, hora do PC] Travadas "do nada" (Discord, Claude, Chrome e o Shell) e animações (pedido do usuário).
+ - DLL das janelas: lia ajustes.txt (TemaTahoe, semaforo.h) e o Registro (tema, cor guardada) na thread da janela de cada app, a cada 0,5-3 s. Com o disco ocupado o app esperava junto. Agora essas leituras e a gravação da cor vão para o pool de threads (src\janelas\macjanela.cpp, controles.cpp, src\comum\semaforo.h). Provado com oplock num ajustes.txt falso de um Electron de teste: quem abriu o arquivo esperou 8,0 s; a janela parou no máximo 23-24 ms.
+ - Shell: pilha de uma parada de 4,9 s em menubar::Update -> ExeOfWindow (OpenProcess + nome do exe). src\shell\apps.cpp guarda exe e AUMID por janela + processo + thread.
+ - Animações: src\shell\ui.cpp, um quadro por vez na fila (o mouse e o teclado não ficam atrás dos quadros a 174 Hz); Quick Look, Time Machine e a prévia do encaixe saíram do timer de 15,6 ms para o relógio da tela.
+ Conferido instalado: 200 s de caça nos apps reais com 0 paradas (disco calmo nesse período); Spotlight, abrir tarefa, lista da bandeja. NÃO conferido na tela: Quick Look, Time Machine, prévia do encaixe; taxa de quadros não medida.
+ DESFAZER: reverter o commit.
diff --git a/src/comum/semaforo.h b/src/comum/semaforo.h
index d0df2bb..c39838b 100644
--- a/src/comum/semaforo.h
+++ b/src/comum/semaforo.h
@@ -17,13 +17,8 @@ enum Kind { FILL, RING, GLYPH };
// lê destaque= e o tema (golden_gate=1 junto com liquid_glass=1 = macOS Golden Gate) do ajustes.txt
struct Estado { bool grafite = false, aqua = false, liquid = false, leopard = false; };
-inline const Estado& Ler(bool force = false) { // force: relê já (o Shell avisou que os ajustes mudaram)
- static Estado st;
- static DWORD lastCheck = 0;
+inline const Estado& Reler(Estado& st) { // espera o disco
static FILETIME lastWrite{};
- DWORD now = GetTickCount();
- if (lastCheck && now - lastCheck < 500 && !force) return st;
- lastCheck = now;
wchar_t ad[MAX_PATH];
DWORD n = GetEnvironmentVariableW(L"APPDATA", ad, MAX_PATH);
if (!n || n >= MAX_PATH) return st;
@@ -50,6 +45,29 @@ inline const Estado& Ler(bool force = false) { // force: relê já (o Shell avi
return st;
}
+inline const Estado& Ler(bool force = false) { // force: relê já (o Shell avisou que os ajustes mudaram)
+ static Estado st;
+ static DWORD lastCheck = 0;
+ DWORD now = GetTickCount();
+ if (lastCheck && now - lastCheck < 500 && !force) return st;
+ const bool primeira = !lastCheck;
+ lastCheck = now | 1;
+#ifdef SEMAFORO_SEM_ESPERA
+ // DLL das janelas (roda na thread da janela dos outros programas): com o disco ocupado o GetFileAttributes
+ // segurava o app por segundos. A conferência vai para o pool; até ela voltar vale o último valor.
+ static volatile LONG lendo = 0;
+ if (!primeira && !force) {
+ if (!InterlockedExchange(&lendo, 1) &&
+ !QueueUserWorkItem([](LPVOID) -> DWORD { Reler(st); InterlockedExchange(&lendo, 0); return 0; }, nullptr, WT_EXECUTELONGFUNCTION))
+ InterlockedExchange(&lendo, 0);
+ return st;
+ }
+#else
+ (void)primeira;
+#endif
+ return Reler(st);
+}
+
inline bool Grafite() { return Ler().grafite; }
// Tema macOS Golden Gate (macOS 27, beta 6 em diante): os botões ganharam volume de novo. Medido nas capturas do
diff --git a/src/janelas/controles.cpp b/src/janelas/controles.cpp
index 73dda79..86adb48 100644
--- a/src/janelas/controles.cpp
+++ b/src/janelas/controles.cpp
@@ -7,6 +7,7 @@
// Cada controle é subclassificado e desenhado por nós (Direct2D num DC, com antisserrilhado); o
// comportamento continua o do Windows. Desfazer (o Shell sai): tudo volta ao original.
#define NOMINMAX
+#define SEMAFORO_SEM_ESPERA // antes dos includes, igual nos dois .cpp da DLL (semaforo.h)
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
diff --git a/src/janelas/macjanela.cpp b/src/janelas/macjanela.cpp
index 8625eee..d4a4f5d 100644
--- a/src/janelas/macjanela.cpp
+++ b/src/janelas/macjanela.cpp
@@ -6,6 +6,7 @@
// Tudo é desfeito com a mensagem "MacJanelaDesfazer" (o Shell manda ao sair).
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
+#define SEMAFORO_SEM_ESPERA // antes dos includes, igual nos dois .cpp da DLL (semaforo.h)
#include <windows.h>
#include <commctrl.h>
#include <uxtheme.h>
@@ -137,7 +138,8 @@ struct Info {
// chunkTop: 1ª linha da foto, a partir do topo
RECT capasVis{}; // retângulo da última foto do fundo dos cantos
DWORD capasAt = 0; // quando foi (refaz a cada 10 s ou quando a janela muda de lugar)
- DWORD layoutAt = 0; // última medição (0 = medir na próxima volta do timer)
+ DWORD layoutAt = 0; // última medição (0 = medir na próxima volta do timer)
+ COLORREF corGravada = CLR_INVALID; // a cor que já está no Registro (não relê a cada volta do timer)
bool remedir = false; // a medição pediu outra (o Chrome refaz a linha): o fim dela não pode apagar o pedido
POINT lastPos{ INT_MIN, INT_MIN }; // onde a janela estava (barra própria: a faixa só anda junto ao arrastar)
// janela de ferramenta com barra (plug-ins VST do Ableton e afins): barra escura compacta, como as janelas de
@@ -162,10 +164,29 @@ struct Info {
SIZE fotoBarraSz{}, fotoMolduraSz{};
};
-bool Dark() {
+// Regra da DLL: na thread da janela do app, nada que espere disco ou Registro. A primeira leitura do processo é
+// direta (precisa do valor para montar a janela); as outras vão para o pool de threads (22/11/2026: Discord, Claude
+// e Chrome paravam segundos quando o disco engasgava).
+void NoPool(LPTHREAD_START_ROUTINE f, volatile LONG* lendo) {
+ if (InterlockedExchange(lendo, 1)) return; // uma leitura por vez
+ if (!QueueUserWorkItem(f, nullptr, WT_EXECUTELONGFUNCTION)) InterlockedExchange(lendo, 0);
+}
+static volatile bool g_escuro;
+static volatile LONG g_lendoEscuro;
+void LerEscuro() {
DWORD v = 1, cb = sizeof(v);
RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", L"AppsUseLightTheme", RRF_RT_REG_DWORD, nullptr, &v, &cb);
- return v == 0;
+ g_escuro = v == 0;
+}
+bool Dark(bool force = false) { // force: o tema do Windows acabou de mudar
+ static DWORD at;
+ DWORD now = GetTickCount() | 1;
+ if (!at || force) { at = now; LerEscuro(); }
+ else if (now - at > 2000) {
+ at = now;
+ NoPool([](LPVOID) -> DWORD { LerEscuro(); InterlockedExchange(&g_lendoEscuro, 0); return 0; }, &g_lendoEscuro);
+ }
+ return g_escuro;
}
float Scale(HWND h) { return GetDpiForWindow(h) / 96.f; }
@@ -903,7 +924,16 @@ COLORREF SavedColor(HWND h = nullptr) {
if (h && GetWindow(h, GW_OWNER)) return SavedColor(nullptr); // diálogo novo: a do programa por enquanto
return CLR_INVALID;
}
-void SaveColor(HWND h, COLORREF c) { DWORD v = c; RegSetKeyValueW(HKEY_CURRENT_USER, COLORS_KEY, ColorKey(h).c_str(), REG_DWORD, &v, sizeof(v)); }
+struct CorGuardar { std::wstring nome; DWORD cor; };
+void SaveColor(HWND h, COLORREF c) { // grava no pool: escrever no Registro também espera o disco
+ auto* g = new CorGuardar{ ColorKey(h), c };
+ if (!QueueUserWorkItem([](LPVOID p) -> DWORD {
+ auto* g = (CorGuardar*)p;
+ RegSetKeyValueW(HKEY_CURRENT_USER, COLORS_KEY, g->nome.c_str(), REG_DWORD, &g->cor, sizeof(g->cor));
+ delete g;
+ return 0;
+ }, g, WT_EXECUTELONGFUNCTION)) delete g;
+}
COLORREF CapColor(Info* in) {
if (in->cap != CLR_INVALID) return in->cap;
@@ -963,24 +993,32 @@ static bool g_propria = true;
bool ProvaAbas(); // mais abaixo: o Chrome de teste (--wacos-teste-abas)
bool BarraPropria() { TemaTahoe(); return g_propria || ProvaAbas(); } // (o Chrome de teste conta como ligado: as provas continuam)
bool TemaGolden() { return TemaTahoe() && g_golden; }
-bool TemaTahoe(bool force) {
- static DWORD at; static bool on;
- DWORD now = GetTickCount();
- if (at && now - at < 3000 && !force) return on;
- at = now ? now : 1;
+static volatile bool g_tahoe;
+static volatile LONG g_lendoTema;
+void LerTema() { // espera o disco
wchar_t path[MAX_PATH];
- if (!GetEnvironmentVariableW(L"APPDATA", path, MAX_PATH)) return on;
+ if (!GetEnvironmentVariableW(L"APPDATA", path, MAX_PATH)) return;
wcscat_s(path, L"\\Shell\\ajustes.txt");
HANDLE f = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, 0, nullptr);
- if (f == INVALID_HANDLE_VALUE) return on;
+ if (f == INVALID_HANDLE_VALUE) return;
char buf[8192]; DWORD n = 0;
- ReadFile(f, buf, sizeof(buf) - 1, &n, nullptr);
+ BOOL ok = ReadFile(f, buf, sizeof(buf) - 1, &n, nullptr);
CloseHandle(f);
+ if (!ok || !n) return; // o Shell está gravando (arquivo vazio por um instante): fica o que valia
buf[n] = 0;
- on = strstr(buf, "liquid_glass=1") != nullptr;
+ g_tahoe = strstr(buf, "liquid_glass=1") != nullptr;
g_golden = strstr(buf, "golden_gate=1") != nullptr;
g_propria = strstr(buf, "barra_mac_propria=0") == nullptr;
- return on;
+}
+bool TemaTahoe(bool force) {
+ static DWORD at;
+ DWORD now = GetTickCount() | 1;
+ if (!at || force) { at = now; LerTema(); }
+ else if (now - at >= 3000) {
+ at = now;
+ NoPool([](LPVOID) -> DWORD { LerTema(); InterlockedExchange(&g_lendoTema, 0); return 0; }, &g_lendoTema);
+ }
+ return g_tahoe;
}
int CornerRadius(HWND h) { return (int)std::lround((TemaTahoe() ? 16 : 12) /* Golden Gate: também 16 pt (medido) */ * Scale(h)); }
@@ -1746,7 +1784,7 @@ void UseColor(Info* in, COLORREF col) {
if (in->transit || (int)(GetTickCount() - in->colorFreezeUntil) < 0) return;
bool stable = col == in->lastRead;
in->lastRead = col;
- if (stable) { in->needColor = false; if (SavedColor(in->owner) != col) SaveColor(in->owner, col); }
+ if (stable) { in->needColor = false; if (in->corGravada != col) { in->corGravada = col; SaveColor(in->owner, col); } }
if (col == in->cap) return;
in->cap = col;
ApplyColors(in);
@@ -2499,7 +2537,7 @@ LRESULT CALLBACK OwnerProc(HWND h, UINT m, WPARAM w, LPARAM l, UINT_PTR, DWORD_P
case WM_SETTEXT: { LRESULT r = DefSubclassProc(h, m, w, l); PaintNC(in); Paint(in); return r; }
case WM_DPICHANGED: { LRESULT r = DefSubclassProc(h, m, w, l); PlaceOverlay(in); return r; }
case WM_SETTINGCHANGE:
- if (l && !lstrcmpiW((LPCWSTR)l, L"ImmersiveColorSet")) { ApplyColors(in); Paint(in); }
+ if (l && !lstrcmpiW((LPCWSTR)l, L"ImmersiveColorSet")) { Dark(true); ApplyColors(in); Paint(in); }
break;
case WM_GETMINMAXINFO: {
// Sem WS_MAXIMIZEBOX/WS_SYSMENU o Windows maximiza sobre o monitor inteiro (por baixo da barra de
@@ -2607,7 +2645,7 @@ void Attach(HWND h, int mode) {
// a barra de menus vai para a barra de menus do Shell (lá em cima), como no Mac
in->menu = GetMenu(h);
if (in->menu) { SetPropW(h, PROP_MENU, (HANDLE)in->menu); SetMenu(h, nullptr); }
- in->cap = in->tool ? RGB(0x2C, 0x2C, 0x2E) : SavedColor(h); // plug-in: a barra escura das janelas de plug-in do Mac
+ in->cap = in->tool ? RGB(0x2C, 0x2C, 0x2E) : (in->corGravada = SavedColor(h)); // plug-in: a barra escura das janelas de plug-in do Mac
if (in->tool) in->needColor = false;
if (in->cap == CLR_INVALID) in->cap = GetSysColor(COLOR_3DFACE); // fundo padrão das janelas (a maioria desses apps)
ApplyColors(in);
diff --git a/src/shell/apps.cpp b/src/shell/apps.cpp
index 8458eee..ce6ee48 100644
--- a/src/shell/apps.cpp
+++ b/src/shell/apps.cpp
@@ -2,6 +2,8 @@
// os abertos (janelas que apareceriam na barra de tarefas) e os recentes. Abrir, ativar, ocultar,
// encerrar, fixar, abrir ao iniciar sessão.
#include "shell.h"
+#include <mutex>
+#include <unordered_map>
#include <memory>
#include <thread>
#include <shlobj.h>
@@ -56,12 +58,44 @@ static std::wstring ExeOfProcess(DWORD pid) {
return OurCanonical(out);
}
+// O que já se perguntou de cada janela. O programa de uma janela não muda; perguntar de novo a cada volta do timer
+// (OpenProcess + QueryFullProcessImageName, que espera o disco) parou a interface do Shell por 4,9 s em 22/11/2026
+// (pilha: menubar::Update -> OfWindow -> ExeOfWindow). A chave é janela + processo + thread: um HWND reaproveitado não casa.
+struct DaJanela {
+ DWORD pid = 0, tid = 0;
+ ULONGLONG desde = 0;
+ std::wstring exe, aumid, aumidProc;
+ bool temAumidProc = false;
+};
+static std::mutex g_janMx;
+static std::unordered_map<HWND, DaJanela> g_jan;
+static DaJanela Guardado(HWND h) {
+ DWORD pid = 0, tid = GetWindowThreadProcessId(h, &pid);
+ std::lock_guard<std::mutex> l(g_janMx);
+ if (g_jan.size() > 1024)
+ for (auto it = g_jan.begin(); it != g_jan.end();) it = IsWindow(it->first) ? std::next(it) : g_jan.erase(it);
+ auto& d = g_jan[h];
+ if (d.pid != pid || d.tid != tid) { d = {}; d.pid = pid; d.tid = tid; d.desde = GetTickCount64(); }
+ return d;
+}
+template <class F> static void Guarda(HWND h, const DaJanela& de, F&& muda) {
+ std::lock_guard<std::mutex> l(g_janMx);
+ auto it = g_jan.find(h);
+ if (it != g_jan.end() && it->second.pid == de.pid && it->second.tid == de.tid) muda(it->second);
+}
+
static std::wstring ExeOfWindow(HWND h) {
- DWORD pid = 0; GetWindowThreadProcessId(h, &pid);
- return ExeOfProcess(pid);
+ DaJanela d = Guardado(h);
+ if (!d.exe.empty() || !d.pid) return d.exe;
+ std::wstring exe = ExeOfProcess(d.pid);
+ if (!exe.empty()) Guarda(h, d, [&](DaJanela& g) { g.exe = exe; });
+ return exe;
}
static std::wstring AumidOfWindow(HWND h) {
+ DaJanela d = Guardado(h);
+ // o da janela pode chegar ou mudar logo depois de ela abrir: só fica guardado depois de 10 s
+ if (!d.aumid.empty()) return d.aumid;
IPropertyStore* ps = nullptr;
std::wstring out;
if (SUCCEEDED(SHGetPropertyStoreForWindow(h, IID_PPV_ARGS(&ps)))) {
@@ -70,13 +104,17 @@ static std::wstring AumidOfWindow(HWND h) {
PropVariantClear(&v);
ps->Release();
}
- if (out.empty()) { // app da Loja cuja janela não traz o AUMID (WhatsApp, WinUI/WebView2): o do processo
- DWORD pid = 0; GetWindowThreadProcessId(h, &pid);
- if (HANDLE hp = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid)) {
- wchar_t buf[APPLICATION_USER_MODEL_ID_MAX_LENGTH] = {}; UINT32 n = APPLICATION_USER_MODEL_ID_MAX_LENGTH;
- if (GetApplicationUserModelId(hp, &n, buf) == ERROR_SUCCESS) out = buf; // sem pacote: APPMODEL_ERROR_NO_APPLICATION
- CloseHandle(hp);
- }
+ if (!out.empty()) {
+ if (GetTickCount64() - d.desde > 10000) Guarda(h, d, [&](DaJanela& g) { g.aumid = out; });
+ return out;
+ }
+ // app da Loja cuja janela não traz o AUMID (WhatsApp, WinUI/WebView2): o do processo, que não muda
+ if (d.temAumidProc) return d.aumidProc;
+ if (HANDLE hp = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, d.pid)) {
+ wchar_t buf[APPLICATION_USER_MODEL_ID_MAX_LENGTH] = {}; UINT32 n = APPLICATION_USER_MODEL_ID_MAX_LENGTH;
+ if (GetApplicationUserModelId(hp, &n, buf) == ERROR_SUCCESS) out = buf; // sem pacote: APPMODEL_ERROR_NO_APPLICATION
+ CloseHandle(hp);
+ Guarda(h, d, [&](DaJanela& g) { g.aumidProc = out; g.temAumidProc = true; });
}
return out;
}
diff --git a/src/shell/encaixe.cpp b/src/shell/encaixe.cpp
index d7ff411..7e819fe 100644
--- a/src/shell/encaixe.cpp
+++ b/src/shell/encaixe.cpp
@@ -73,8 +73,19 @@ int Target(HWND h, RECT* t) {
return 0;
}
+const UINT WM_EN_FRAME = WM_APP + 140;
+double g_fadeAt; // quando a prévia começou a aparecer
+
LRESULT CALLBACK PrevProc(HWND h, UINT m, WPARAM w, LPARAM l) {
if (m == WM_NCHITTEST) return HTTRANSPARENT;
+ if (m == WM_EN_FRAME) { // aparecendo: ~90 ms, um passo por quadro da tela (eram 4 passos de um timer de 15,6 ms)
+ if (!g_kind || g_alpha == 255) { ui::FrameClock(h, WM_EN_FRAME, false); return 0; }
+ double t = std::clamp((anim::Now() - g_fadeAt) / 90.0, 0.0, 1.0);
+ g_alpha = (BYTE)(60 + 195 * (1 - (1 - t) * (1 - t)));
+ BLENDFUNCTION bf{ AC_SRC_OVER, 0, g_alpha, AC_SRC_ALPHA };
+ UpdateLayeredWindow(h, nullptr, nullptr, nullptr, nullptr, nullptr, 0, &bf, ULW_ALPHA);
+ return 0;
+ }
return DefWindowProcW(h, m, w, l);
}
@@ -135,15 +146,8 @@ void Hide() {
}
void Show(int kind, RECT t) {
- if (kind == g_kind && EqualRect(&t, &g_target)) {
- if (g_alpha < 255) { // aparecendo: ~100 ms
- g_alpha = (BYTE)std::min(255, g_alpha + 50);
- BLENDFUNCTION bf{ AC_SRC_OVER, 0, g_alpha, AC_SRC_ALPHA };
- UpdateLayeredWindow(g_prev, nullptr, nullptr, nullptr, nullptr, nullptr, 0, &bf, ULW_ALPHA);
- }
- return;
- }
- if (!g_kind) g_alpha = 60;
+ if (kind == g_kind && EqualRect(&t, &g_target)) return;
+ if (!g_kind) { g_alpha = 60; g_fadeAt = anim::Now(); ui::FrameClock(g_prev, WM_EN_FRAME, true); }
g_kind = kind; g_target = t;
Draw(t, g_drag);
// logo atrás da janela arrastada (acima das outras)
diff --git a/src/shell/quicklook.cpp b/src/shell/quicklook.cpp
index ab72b0a..d0e36a1 100644
--- a/src/shell/quicklook.cpp
+++ b/src/shell/quicklook.cpp
@@ -33,6 +33,7 @@
namespace {
const UINT WM_QL_READY = WM_APP + 91;
+const UINT WM_QL_FRAME = WM_APP + 141; // quadro da animação de abrir e fechar (relógio da tela)
const UINT WM_QL_MEDIA = WM_APP + 92; // evento do MFPlay (vídeo/música pronto, terminou, erro)
const float BAR = 38, R = 12, PAD = 0;
HWND g_wnd;
@@ -177,7 +178,6 @@ float Sc() { return ui::Scale(g_wnd); }
float g_qlOp = 1, g_qlSc = 1;
double g_qlAnimT0 = -1;
bool g_qlAnimOut;
-const UINT_PTR T_QLANIM = 9;
void CloseNow();
void ApplyFade() {
if (!g_back) return;
@@ -193,7 +193,7 @@ void AnimStep() {
else { g_qlOp = e; g_qlSc = 0.94f + 0.06f * e; }
ApplyFade();
if (t >= 1) {
- KillTimer(g_wnd, T_QLANIM);
+ ui::FrameClock(g_wnd, WM_QL_FRAME, false);
g_qlAnimT0 = -1;
if (g_qlAnimOut) { g_qlAnimOut = false; g_qlOp = g_qlSc = 1; CloseNow(); }
else { g_qlOp = g_qlSc = 1; ApplyFade(); }
@@ -202,7 +202,7 @@ void AnimStep() {
void AnimStart(bool out) {
g_qlAnimOut = out;
g_qlAnimT0 = anim::Now();
- SetTimer(g_wnd, T_QLANIM, 8, nullptr);
+ ui::FrameClock(g_wnd, WM_QL_FRAME, true);
}
// Por cima do Finder (como o painel do Mac): fica "sempre visível" enquanto a janela da frente é do Finder ou do
@@ -1190,8 +1190,10 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
return 0;
}
if (w == 8) { KeepTop(); return 0; }
- if (w == T_QLANIM) { AnimStep(); return 0; }
break;
+ case WM_QL_FRAME:
+ if (g_qlAnimT0 >= 0) AnimStep(); else ui::FrameClock(h, WM_QL_FRAME, false);
+ return 0;
case WM_QL_READY: {
auto* r = (std::tuple<int, UINT, UINT, std::vector<BYTE>>*)l;
if (std::get<0>(*r) == g_gen && !g_hasVideo) {
@@ -1369,7 +1371,7 @@ std::wstring quicklook::Path() { return IsOpen() ? g_path : L""; }
namespace {
void CloseNow() {
if (!g_wnd) return;
- KillTimer(g_wnd, T_QLANIM); g_qlAnimT0 = -1; g_qlAnimOut = false; g_qlOp = g_qlSc = 1;
+ ui::FrameClock(g_wnd, WM_QL_FRAME, false); g_qlAnimT0 = -1; g_qlAnimOut = false; g_qlOp = g_qlSc = 1;
MediaStop();
HandlerStop();
ZoomReset();
diff --git a/src/shell/tempo.cpp b/src/shell/tempo.cpp
index 6ab891b..af6fee3 100644
--- a/src/shell/tempo.cpp
+++ b/src/shell/tempo.cpp
@@ -17,7 +17,7 @@
namespace {
-const UINT T_ANIM = 1;
+const UINT WM_TM_FRAME = WM_APP + 142; // quadro (relógio da tela)
struct Item { std::wstring name, src; bool dir = false; ULONGLONG mtime = 0; };
struct Snap { ULONGLONG t = 0; std::vector<Item> items; }; // t = 0: agora
@@ -337,7 +337,7 @@ void Paint() {
ui::GpuEnd(g_s);
}
-void HideNow() { KillTimer(g_wnd, T_ANIM); ShowWindow(g_wnd, SW_HIDE); g_open = g_closing = false; g_snaps.clear(); }
+void HideNow() { ui::FrameClock(g_wnd, WM_TM_FRAME, false); ShowWindow(g_wnd, SW_HIDE); g_open = g_closing = false; g_snaps.clear(); }
void Close() { if (!g_open || g_closing) return; g_closing = true; g_at = anim::Now(); }
void Go(int to) {
@@ -368,8 +368,8 @@ bool In(D2D1_RECT_F r, D2D1_POINT_2F p) { return p.x >= r.left && p.x < r.right
LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {
switch (m) {
- case WM_TIMER:
- if (w == T_ANIM) {
+ case WM_TM_FRAME:
+ if (g_open) {
double now = anim::Now(), dt = std::min(100.0, now - g_lastTick); g_lastTick = now;
float diff = g_sel - g_pos;
g_pos += diff * (1 - std::exp(-(float)dt / 110.f));
@@ -440,6 +440,6 @@ void tempo::Enter() {
bool att = ft && ft != me && AttachThreadInput(me, ft, TRUE);
SetForegroundWindow(g_wnd); SetFocus(g_wnd);
if (att) AttachThreadInput(me, ft, FALSE);
- SetTimer(g_wnd, T_ANIM, 16, nullptr);
+ ui::FrameClock(g_wnd, WM_TM_FRAME, true);
Log(L"time machine: %zu versões de %ls (backup: %ls)", g_snaps.size(), g_folder.c_str(), g_root.empty() ? L"nenhum" : g_root.c_str());
}
diff --git a/src/shell/ui.cpp b/src/shell/ui.cpp
index 79c47d0..729e57c 100644
--- a/src/shell/ui.cpp
+++ b/src/shell/ui.cpp
@@ -558,6 +558,20 @@ void ui::FrameAck(HWND hwnd, UINT msg) {
for (auto* c : g_clocks) if (c->hwnd == hwnd && c->msg == msg) { c->acks = true; c->pending = false; return; }
}
+// Um quadro por vez na fila, para todas as animações: o quadro saiu da fila = o relógio pode mandar o próximo. Sem
+// isso, a 174 Hz, um desenho de mais de 5,7 ms enchia a fila de quadros, e mensagem postada passa na frente do mouse e
+// do teclado: a animação e o resto da interface engasgavam juntos. É gancho da thread (vale também dentro dos laços de
+// menu e de arrastar).
+static LRESULT CALLBACK QuadroSaiu(int code, WPARAM w, LPARAM l) {
+ if (code >= 0 && w == PM_REMOVE && l) {
+ auto* m = (const MSG*)l;
+ if (m->message >= WM_USER)
+ for (auto* c : g_clocks)
+ if (c->hwnd == m->hwnd && c->msg == m->message) { c->pending = false; break; }
+ }
+ return CallNextHookEx(nullptr, code, w, l);
+}
+
void ui::FrameClock(HWND hwnd, UINT msg, bool on) {
for (auto* c : g_clocks)
if (c->hwnd == hwnd && c->msg == msg) {
@@ -567,6 +581,14 @@ void ui::FrameClock(HWND hwnd, UINT msg, bool on) {
}
if (!on) return;
auto* c = new Clock{ hwnd, msg, true, CreateEventW(nullptr, FALSE, FALSE, nullptr) };
+ {
+ static thread_local HHOOK gancho;
+ DWORD me = GetCurrentThreadId();
+ if (GetWindowThreadProcessId(hwnd, nullptr) == me) {
+ if (!gancho) gancho = SetWindowsHookExW(WH_GETMESSAGE, QuadroSaiu, nullptr, me);
+ c->acks = gancho != nullptr;
+ }
+ }
g_clocks.push_back(c);
std::thread([c] {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);