fix(windows): resolve GDI leaks in Settings UI and System Tray - #394
fix(windows): resolve GDI leaks in Settings UI and System Tray#394so-sai wants to merge 3 commits into
Conversation
- Store HFONT as member and call DeleteObject to prevent GDI leak on UI refresh - Call DestroyIcon in SystemTray destructor to clean up handles
- Thêm cờ /utf-8 vào CMake để MSVC biên dịch đúng string UTF-8 - Thêm pragma code_page(65001) vào resources.rc để fix lỗi font trên Title Bar
|
Thêm cờ
|
|
-Tối ưu hóa logic bắt phím Shift bằng phép XOR (
|
…sing keycode mappings - keyboard_hook.cpp: XOR CapsLock with Shift for correct case (Shift+dd → Đ) - app_compat.cpp: Add zalo.exe to slow injection list - keyboard_hook.cpp: Add missing VkToMacKeycode mappings for period (0x2F), comma (0x2B), slash (0x2C), and number 1 (0x12) so Rust engine receives sentence-ending punctuation (. ! ?) and auto-capitalize works correctly
e971d67 to
10cf3f5
Compare
|
Sửa lỗi tính năng Tự động viết hoa (Auto-Capitalize) không hoạt động: |
Vị trí: platforms/windows/src/settings_window.cpp:141
Vấn đề: hFont được tạo cục bộ trong CreateControls() và gán cho các control tĩnh thông qua WM_SETFONT nhưng không bao giờ giải phóng bằng DeleteObject. Khi mở lại màn hình settings hoặc khi đổi DPI, font mới được tạo liên tục gây tích tụ leak.
Đề xuất: Đưa hFont_ làm member của lớp SettingsWindow để giải phóng khi hủy đối tượng hoặc trước khi tạo font mới (khi đổi DPI).
diff
diff --git a/platforms/windows/src/settings_window.h b/platforms/windows/src/settings_window.h
index 52f2dcd..bba0766 100644
--- a/platforms/windows/src/settings_window.h
+++ b/platforms/windows/src/settings_window.h
@@ -34,6 +34,7 @@ private:
HWND hwnd_ = nullptr;
HWND cmbMethod_ = nullptr;
bool visible_ = false;
HFONT hFont_ = nullptr;
// Custom painted section positions
diff
diff --git a/platforms/windows/src/settings_window.cpp b/platforms/windows/src/settings_window.cpp
index b77255a..702eab9 100644
--- a/platforms/windows/src/settings_window.cpp
+++ b/platforms/windows/src/settings_window.cpp
@@ -48,6 +48,7 @@ SettingsWindow& SettingsWindow::Instance() {
}
SettingsWindow::~SettingsWindow() {
if (hFont_) { DeleteObject(hFont_); }
if (hwnd_) {
DestroyWindow(hwnd_);
}
@@ -138,7 +139,8 @@ void SettingsWindow::CreateControls() {
// Create DPI-scaled font
int fontSize = Scale(13, dpi);
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, L"Segoe UI");
@@ -165,7 +167,7 @@ void SettingsWindow::CreateControls() {
WS_CHILD | WS_VISIBLE | SS_LEFT | SS_CENTERIMAGE,
labelX, y, labelWidth, rowHeight,
hwnd_, NULL, hInst, NULL);
Vị trí: platforms/windows/src/system_tray.cpp:34,59
Vấn đề: Icon được load qua LoadImageW trả về một handle riêng biệt cần được thu hồi bằng DestroyIcon. Hàm Destroy() hiện tại chỉ xóa khay hệ thống (NIM_DELETE) mà chưa hủy handle của icon này.
Đề xuất: Gọi DestroyIcon(nid_.hIcon) khi giải phóng SystemTray.
diff
diff --git a/platforms/windows/src/system_tray.cpp b/platforms/windows/src/system_tray.cpp
index 85e7a4d..029920a 100644
--- a/platforms/windows/src/system_tray.cpp
+++ b/platforms/windows/src/system_tray.cpp
@@ -57,6 +57,7 @@ bool SystemTray::Create(HWND hwnd) {
void SystemTray::Destroy() {
if (created_) {
Shell_NotifyIconW(NIM_DELETE, &nid_);
}