A new style desktop shell for Windows 11: menu bar, Dock, Finder, Spotlight, Control Center and Liquid Glass, in native C++.
Rust
Spotlight/Launchpad: inline IME composition; Apps icons ready before opening
Eternity070628138c3a694fd1
diff --git a/src/comum/ime.h b/src/comum/ime.hnew file mode 100644index 0000000..58e6bb0--- /dev/null+++ b/src/comum/ime.h@@ -0,0 +1,63 @@+// Composição do IME (coreano, japonês, chinês) direto num campo nosso que só cresce no fim (Spotlight, Launchpad).+// Sem isto o Windows abria a janelinha de composição dele em cima do campo e o texto só chegava (WM_CHAR) quando a+// sílaba era fechada: em coreano, só depois de digitar a próxima letra (pedido de 22/11/2026). Agora a sílaba em+// composição já aparece no fim do texto (e já busca), e é trocada pela definitiva quando o IME a fecha.+#pragma once+#include <windows.h>+#include <imm.h>+#include <string>+#pragma comment(lib, "imm32.lib")++namespace ime {++struct State { std::wstring comp; }; // a sílaba em composição que está no fim do texto agora++// tira a composição do fim do texto (só se ela ainda estiver lá: o texto pode ter sido limpo nesse meio tempo)+inline void Drop(std::wstring& q, State& st) {+ if (!st.comp.empty() && q.size() >= st.comp.size() && !q.compare(q.size() - st.comp.size(), st.comp.size(), st.comp))+ q.resize(q.size() - st.comp.size());+ st.comp.clear();+}++// Trata as mensagens do IME. true = era do IME (devolva *res). *changed = o texto mudou (refazer a busca/desenho).+inline bool Handle(HWND h, UINT m, WPARAM w, LPARAM l, std::wstring& q, State& st, bool* changed, LRESULT* res, size_t maxLen = 200) {+ *changed = false;+ switch (m) {+ case WM_IME_SETCONTEXT: // sem a janelinha de composição do Windows (a sílaba aparece no nosso campo)+ *res = DefWindowProcW(h, m, w, l & ~ISC_SHOWUICOMPOSITIONWINDOW);+ return true;+ case WM_IME_STARTCOMPOSITION:+ *res = 0;+ return true;+ case WM_IME_COMPOSITION: {+ HIMC c = ImmGetContext(h);+ if (!c) return false;+ auto get = [c](DWORD which) {+ std::wstring s;+ LONG b = ImmGetCompositionStringW(c, which, nullptr, 0);+ if (b > 0) { s.resize(b / sizeof(wchar_t)); ImmGetCompositionStringW(c, which, &s[0], b); }+ return s;+ };+ // o coreano manda as duas juntas: a sílaba que fechou (resultado) e a nova que começou (composição)+ if (l & GCS_RESULTSTR) { Drop(q, st); q += get(GCS_RESULTSTR); *changed = true; }+ if (l & GCS_COMPSTR) { Drop(q, st); st.comp = get(GCS_COMPSTR); q += st.comp; *changed = true; }+ if (q.size() > maxLen) { q.resize(maxLen); st.comp.clear(); }+ ImmReleaseContext(h, c);+ *res = 0; // sem DefWindowProc: senão o resultado chegaria de novo como WM_CHAR+ return true;+ }+ case WM_IME_ENDCOMPOSITION: // cancelada (Esc no IME): a sílaba sai+ if (!st.comp.empty()) { Drop(q, st); *changed = true; }+ *res = 0;+ return true;+ }+ return false;+}++// a janela vai fechar: o IME esquece a composição (senão ela voltava na próxima abertura)+inline void Cancel(HWND h, State& st) {+ if (HIMC c = ImmGetContext(h)) { ImmNotifyIME(c, NI_COMPOSITIONSTR, CPS_CANCEL, 0); ImmReleaseContext(h, c); }+ st.comp.clear();+}++} // namespace imediff --git a/src/shell/launchpad.cpp b/src/shell/launchpad.cppindex 76ed5c2..cd4ace5 100644--- a/src/shell/launchpad.cpp+++ b/src/shell/launchpad.cpp@@ -29,6 +29,7 @@ static ID2D1Bitmap* StyledBitmap(ID2D1RenderTarget* rt, UINT w, UINT h, const st#include <thread>#include "../comum/idioma.h"#include "../menu/context_menu.h"+#include "../comum/ime.h"namespace {@@ -739,9 +740,11 @@ void CompAnimate(bool closing) {ui::Comp()->Commit();}+ime::State g_ime; // sílaba do IME em composição no fim do g_query (comum/ime.h)void Close() {if (!g_open || g_closing) return;g_closing = true;+ ime::Cancel(g_wnd, g_ime);g_closingAt = anim::Now();if (g_comp) {ui::FrameClock(g_wnd, WM_LP_FRAME, false);@@ -783,6 +786,13 @@ void GoPage(int p) {}LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {+ { // IME (coreano...): a sílaba em composição direto na busca+ LRESULT r = 0; bool changed = false;+ if (ime::Handle(h, m, w, l, g_query, g_ime, &changed, &r)) {+ if (changed) { { std::lock_guard<std::mutex> lk(g_mu); g_page = 0; Filter(); } g_apScroll = 0; Paint(); }+ return r;+ }+ }if (m == WM_INITMENUPOPUP || m == WM_DRAWITEM || m == WM_MEASUREITEM || m == WM_MENUCHAR) { // submenus das extensõesLRESULT res = 0;if (ctxmenu::ForwardOwnerMsg(m, w, l, &res)) return res;diff --git a/src/shell/spotlight.cpp b/src/shell/spotlight.cppindex d11ee75..a0946e4 100644--- a/src/shell/spotlight.cpp+++ b/src/shell/spotlight.cpp@@ -22,6 +22,7 @@#include "../comum/idioma.h"#include "../menu/context_menu.h"#include "../comum/vidro.h"+#include "../comum/ime.h"#include <set>#pragma comment(lib, "winhttp.lib")#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll" no_namespace rename("EOF", "AdoEOF")@@ -68,7 +69,9 @@ void Metricas() {}const float LEO_ROW = 20, LEO_COL = 112; // Leopard: linhas de 20 e a coluna das categoriasconst UINT WM_SP_FILES = WM_APP + 60, WM_SP_ICON = WM_APP + 61, WM_SP_APPS = WM_APP + 62, WM_SP_FRAME = WM_APP + 63, WM_SP_SUGG = WM_APP + 64;-const UINT_PTR T_SEARCH = 1, T_CARET = 2, T_ICONS = 3, T_REGRAB = 4;+const UINT_PTR T_SEARCH = 1, T_CARET = 2, T_ICONS = 3, T_REGRAB = 4, T_UPLOAD = 9;+const UINT WM_SP_PRELOADED = WM_APP + 66; // os ícones dos apps foram pré-carregados: sobem para a GPU com o painel fechado+ime::State g_ime; // sílaba do IME em composição no fim do g_queryenum Kind { K_APP, K_SETTING, K_DOC, K_FOLDER, K_IMAGE, K_MEDIA, K_OTHER, K_CALC, K_WEB };@@ -677,6 +680,12 @@ void LoadIcon(const Result& copy, const std::wstring& key, int px) {}}}+ // guardado no tamanho em que aparece (a grade usa 77, com folga): os ~300 apps pré-carregados a 256 px+ // seriam ~75 MB de memória; a 128 são ~20 MB, e a mesma nitidez na tela+ if (ok && !got.lowres) {+ static const UINT keep = (UINT)std::clamp((int)std::ceil(128.f * GetDpiForSystem() / 96.f), 96, 256);+ ui::Downscale(got.w, got.h, got.px, keep);+ }} else if (copy.kind == K_SETTING) {std::wstring png = apps::PackIconByName(L"System Settings");ok = !png.empty() && ui::LoadPng(png, got.w, got.h, got.px);@@ -722,6 +731,56 @@ ID2D1Bitmap* IconFor(ID2D1RenderTarget* rt, const Result& r) {return ic.bmp;}+// ---- Ícones dos apps prontos antes de abrir (pedido de 22/11/2026: o Apps da tecla Windows abria com ícones+// faltando e iam aparecendo). Antes eles só eram pedidos quando a célula era desenhada (duas threads, até 3 subindo+// para a GPU por quadro), então a primeira abertura depois de o Shell iniciar mostrava buracos. Agora, assim que a+// lista de apps fica pronta, uma thread de fundo carrega os ícones de todos, e com o painel fechado eles sobem para a+// GPU aos poucos (8 a cada 16 ms). Na abertura já está tudo lá.+std::atomic<bool> g_preloading;+void PreloadIcons() {+ if (g_preloading.exchange(true)) return;+ std::vector<Result> list;+ { std::lock_guard<std::mutex> l(g_mu); for (auto& a : g_apps) list.push_back({ K_APP, a.name, a.parsing, L"", 0 }); }+ std::thread([list] {+ CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_BEGIN);+ int n = 0;+ for (auto& r : list) {+ std::wstring key = IconKey(r);+ {+ std::lock_guard<std::mutex> l(g_iconMu);+ auto& ic = g_icons[key];+ if (ic.loading || !ic.px.empty() || ic.bmp || ic.failed) continue;+ ic.loading = true;+ }+ LoadIcon(r, key, 96);+ n++;+ }+ SetThreadPriority(GetCurrentThread(), THREAD_MODE_BACKGROUND_END);+ CoUninitialize();+ Log(L"spotlight: ícones de %d apps carregados antes de abrir", n);+ g_preloading = false;+ if (g_wnd) PostMessageW(g_wnd, WM_SP_PRELOADED, 0, 0);+ }).detach();+}+// sobe até `max` ícones de apps para a GPU (o contexto de ui::Gpu(): os bitmaps valem no desenho do painel);+// false = não sobrou nenhum+bool UploadIcons(int max) {+ ID2D1DeviceContext* dc = ui::Gpu();+ if (!dc) return false;+ const std::wstring st = ui::IconStyle(), pre = L"app:" + ui::IconStyleKey() + L":";+ std::lock_guard<std::mutex> l(g_iconMu);+ int n = 0;+ for (auto& [k, ic] : g_icons) {+ if (ic.bmp || ic.px.empty() || k.compare(0, pre.size(), pre)) continue;+ if (n++ >= max) return true;+ if (st != L"padrao") ui::StyleIcon(ic.w, ic.h, ic.px, st); // o mesmo do IconFor+ ic.bmp = ui::Bitmap(dc, ic.w, ic.h, ic.px);+ ic.px.clear(); ic.px.shrink_to_fit();+ }+ return false;+}+// ---- resultados e linhasstd::vector<Result> g_files; // última resposta do índicestd::wstring g_calc;@@ -2016,6 +2075,7 @@ void Grab(HWND w) {void Close(bool restore = false) {if (!g_open) return;g_open = false;+ ime::Cancel(g_wnd, g_ime);menubar::SoundChanged(false); // a cápsula da lupa da barra saig_edit = g_dragging = false; g_press = -1; g_cellAt.clear();KillTimer(g_wnd, T_REGRAB);@@ -2250,13 +2310,19 @@ void AppsMenu(HWND h, LPARAM l) {}LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {+ { // IME (coreano...): a sílaba em composição direto no campo (comum/ime.h)+ if (m == WM_IME_COMPOSITION && g_selAll) { g_query.clear(); g_selAll = false; g_ime.comp.clear(); } // Ctrl+A: substitui tudo+ LRESULT r = 0; bool changed = false;+ if (ime::Handle(h, m, w, l, g_query, g_ime, &changed, &r)) { if (changed) QueryChanged(); return r; }+ }if (m == WM_INITMENUPOPUP || m == WM_DRAWITEM || m == WM_MEASUREITEM || m == WM_MENUCHAR) { // submenus das extensões (Abrir com, Enviar para)LRESULT res = 0;if (ctxmenu::ForwardOwnerMsg(m, w, l, &res)) return res;}switch (m) {case WM_PAINT: { PAINTSTRUCT ps; BeginPaint(h, &ps); EndPaint(h, &ps); Paint(); return 0; }- case WM_SP_APPS: if (g_open && (!g_query.empty() || ModePanel())) Refresh(); return 0;+ case WM_SP_APPS: PreloadIcons(); if (g_open && (!g_query.empty() || ModePanel())) Refresh(); return 0;+ case WM_SP_PRELOADED: if (!g_open) SetTimer(h, T_UPLOAD, 16, nullptr); return 0;case WM_SP_ICON: // ícones chegam aos montes (a grade de apps): um redesenho só para váriosSetTimer(h, T_ICONS, 24, nullptr);return 0;@@ -2306,6 +2372,7 @@ LRESULT CALLBACK Proc(HWND h, UINT m, WPARAM w, LPARAM l) {} else if (w == T_CARET) { g_caretOn = !g_caretOn; Paint(); }else if (w == T_REGRAB) { KillTimer(h, T_REGRAB); if (g_open) Grab(h); }else if (w == T_ICONS) { KillTimer(h, T_ICONS); Paint(); }+ else if (w == T_UPLOAD) { if (g_open || !UploadIcons(8)) KillTimer(h, T_UPLOAD); } // aberto: o desenho sobe os que faltaremelse if (w == T_HOLD) { // segurou um app: a grade treme (como no Launchpad)KillTimer(h, T_HOLD);if (g_press >= 0 && !g_edit && CanArrange()) StartEdit();