Skip to content

Commit 1e97cdc

Browse files
feat: add font cache refresh on Shift key press in context menu
1 parent 77db347 commit 1e97cdc

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

src/shell/contextmenu/hooks.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "blook/blook.h"
1010
#include <atlcomcli.h>
1111
#include <atomic>
12+
#include <print>
1213
#include <shobjidl_core.h>
1314
#include <thread>
1415

@@ -32,6 +33,12 @@ mb_shell::track_popup_menu(mb_shell::menu menu, int x, int y,
3233
menu_render.rt->last_time = menu_render.rt->clock.now();
3334
perf.end("menu_render::create");
3435

36+
// If holds Shift key when opening the menu, refresh the font cache
37+
if (GetKeyState(VK_SHIFT) & 0x8000) {
38+
std::println("Refreshing font cache...");
39+
menu_render.reset_fons_cache();
40+
}
41+
3542
static HWND window = nullptr;
3643
window = (HWND)menu_render.rt->hwnd();
3744
// set keyboard hook to handle keyboard input

src/shell/contextmenu/menu_render.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "menu_render.h"
2+
#include "shell/utils.h"
23
#define GLFW_EXPOSE_NATIVE_WIN32
34
#include "GLFW/glfw3native.h"
45
#include "Windows.h"
@@ -141,4 +142,48 @@ menu_render &menu_render::operator=(menu_render &&t) {
141142
selected_menu = std::move(t.selected_menu);
142143
return *this;
143144
}
145+
// struct NVGcontext {
146+
// NVGparams params;
147+
// float* commands;
148+
// int ccommands;
149+
// int ncommands;
150+
// float commandx, commandy;
151+
// NVGstate states[NVG_MAX_STATES];
152+
// int nstates;
153+
// NVGpathCache* cache;
154+
// float tessTol;
155+
// float distTol;
156+
// float fringeWidth;
157+
// float devicePxRatio;
158+
// struct FONScontext* fs;
159+
// int fontImages[NVG_MAX_FONTIMAGES];
160+
// int fontImageIdx;
161+
// int drawCallCount;
162+
// int fillTriCount;
163+
// int strokeTriCount;
164+
// int textTriCount;
165+
// };
166+
// HACK: By finding the third readable pointer from NVGcontext, we can get the FONScontext
167+
struct FONScontext;
168+
extern "C" int fonsResetAtlas(FONScontext* stash, int width, int height);
169+
void menu_render::reset_fons_cache() {
170+
if (!rt)
171+
return;
172+
auto nvg = rt->nvg;
173+
char* ptr = reinterpret_cast<char *>(nvg);
174+
size_t offset = sizeof(NVGparams) + sizeof(float *);
175+
int ptr_count = 0;
176+
for (size_t i = 0; i < 1024; i += 4) {
177+
void **p = reinterpret_cast<void **>(ptr + offset + i);
178+
if (is_memory_readable(*p)) {
179+
ptr_count++;
180+
if (ptr_count == 2) {
181+
auto fons = reinterpret_cast<struct FONScontext *>(*p);
182+
fonsResetAtlas(fons, 512, 512);
183+
return;
184+
}
185+
}
186+
}
187+
188+
}
144189
}; // namespace mb_shell

src/shell/contextmenu/menu_render.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct menu_render {
2020
const menu_render &operator=(const menu_render &) = delete;
2121
menu_render(menu_render &&t);
2222
menu_render &operator=(menu_render &&t);
23+
void reset_fons_cache();
2324
static menu_render create(int x, int y, menu menu, bool run_js = true);
2425
};
2526
} // namespace mb_shell

src/shell/script/script.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shell/script/ts/src/config_page/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@ export const showConfigPage = () => {
7474
shell.breeze.set_can_reload_js(false);
7575
const win = shell.breeze_ui.window.create_ex("Breeze Config", 800, 600, () => {
7676
shell.breeze.set_can_reload_js(true)
77-
existingConfigWindow = null;
77+
if (existingConfigWindow === win)
78+
existingConfigWindow = null;
7879
});
79-
if (existingConfigWindow)
80+
if (existingConfigWindow)
8081
existingConfigWindow.close();
8182
existingConfigWindow = win;
82-
83+
8384
const widget = shell.breeze_ui.widgets_factory.create_flex_layout_widget();
8485
const renderer = createRenderer(widget);
8586
renderer.render(React.createElement(ConfigApp, null));

0 commit comments

Comments
 (0)