feat(ui): 重做启动器界面并修复 DPI 发糊
- 交叉编译补嵌 runner.exe.manifest:GNUn res 不再丢掉 DPI 声明,缩放屏不再位图拉伸 - main.cpp 建窗前自行声明 Per-Monitor V2 DPI 感知(三级回退) - win32_window 初始窗口按显示器工作区上限收缩,避免 150% 缩放后超出屏幕 - 重做主题:中性石墨底 + 高对比正文、统一字号/间距/圆角令牌、Segoe UI + 雅黑字体栈 - 首页/下载/设置/关于四页重排,宽屏自适应、小窗不溢出 - 修复下拉框字体丢失、封面遮罩盖住占位、任务状态未翻译等问题 - 截图脚本:注入 CJK/图标字体、runAsync 取像素、补小窗回归用例
This commit is contained in:
1 parent
6ee2e8bead
commit
e67cc63998
10 files changed
+2518
-1080
No files matched your search
@@ -5,8 +5,81 @@
|
||||
#include "flutter_window.h"
|
||||
#include "utils.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Enable DPI awareness (Per-Monitor V2 when available).
|
||||
//
|
||||
// The runner.exe.manifest normally declares this, but the mingw/windres cross
|
||||
// build does not embed the manifest the way the Visual Studio generator does.
|
||||
// A DPI-unaware process gets bitmap-stretched by Windows on a 125% / 150%
|
||||
// scaled display, which makes the whole UI (especially small CJK text) look
|
||||
// blurry. Declaring it again before any window exists costs nothing and does
|
||||
// not depend on the manifest being present.
|
||||
//
|
||||
// Every API is resolved through GetProcAddress: it keeps the binary working on
|
||||
// older systems and does not require the current SDK / mingw headers to declare
|
||||
// DPI_AWARENESS_CONTEXT.
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4191) // FARPROC to typed function pointer, on purpose
|
||||
#endif
|
||||
|
||||
BOOL TryPerMonitorV2() {
|
||||
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 == (HANDLE)-4
|
||||
using Fn = BOOL(WINAPI*)(HANDLE);
|
||||
HMODULE user32 = ::GetModuleHandleW(L"user32.dll");
|
||||
if (user32 == nullptr) return FALSE;
|
||||
auto set_context = reinterpret_cast<Fn>(
|
||||
::GetProcAddress(user32, "SetProcessDpiAwarenessContext"));
|
||||
if (set_context == nullptr) return FALSE;
|
||||
// Cast through INT_PTR: plain -4 to pointer is C4312 at /W4.
|
||||
return set_context(reinterpret_cast<HANDLE>(static_cast<INT_PTR>(-4)));
|
||||
}
|
||||
|
||||
void TryPerMonitor() {
|
||||
// Windows 8.1+: PROCESS_PER_MONITOR_DPI_AWARE == 2
|
||||
using Fn = HRESULT(WINAPI*)(int);
|
||||
HMODULE shcore = ::LoadLibraryW(L"shcore.dll");
|
||||
if (shcore == nullptr) return;
|
||||
auto set_awareness =
|
||||
reinterpret_cast<Fn>(::GetProcAddress(shcore, "SetProcessDpiAwareness"));
|
||||
if (set_awareness != nullptr) {
|
||||
// E_ACCESSDENIED means the manifest already set awareness: still fine.
|
||||
set_awareness(2);
|
||||
}
|
||||
::FreeLibrary(shcore);
|
||||
}
|
||||
|
||||
void TrySystemDpiAware() {
|
||||
// Windows Vista+: system DPI awareness, better than nothing.
|
||||
using Fn = BOOL(WINAPI*)();
|
||||
HMODULE user32 = ::GetModuleHandleW(L"user32.dll");
|
||||
if (user32 == nullptr) return;
|
||||
auto set_aware =
|
||||
reinterpret_cast<Fn>(::GetProcAddress(user32, "SetProcessDPIAware"));
|
||||
if (set_aware != nullptr) set_aware();
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
void EnableDpiAwareness() {
|
||||
// When the manifest already declared awareness, SetProcessDpiAwarenessContext
|
||||
// returns FALSE; fall back to the 8.1 and Vista entry points. All three
|
||||
// failing is harmless: the app still starts, it just scales blurrily.
|
||||
if (TryPerMonitorV2()) return;
|
||||
TryPerMonitor();
|
||||
TrySystemDpiAware();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
|
||||
_In_ wchar_t *command_line, _In_ int show_command) {
|
||||
// Must run before the first window is created to take effect.
|
||||
EnableDpiAwareness();
|
||||
|
||||
// Attach to console when present (e.g., 'flutter run') or create a
|
||||
// new console when running with a debugger.
|
||||
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
|
||||
|
||||
@@ -134,11 +134,27 @@ bool Win32Window::Create(const std::wstring& title,
|
||||
UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
|
||||
double scale_factor = dpi / 96.0;
|
||||
|
||||
// Cap the initial size to the monitor work area. 1280x720 logical is
|
||||
// 1920x1080 physical at 150% scaling, which no longer fits on a 1080p
|
||||
// screen; clamping keeps the window usable instead of hanging off-screen.
|
||||
int physical_width = Scale(size.width, scale_factor);
|
||||
int physical_height = Scale(size.height, scale_factor);
|
||||
MONITORINFO monitor_info{};
|
||||
monitor_info.cbSize = sizeof(MONITORINFO);
|
||||
if (::GetMonitorInfoW(monitor, &monitor_info)) {
|
||||
const int max_width =
|
||||
(monitor_info.rcWork.right - monitor_info.rcWork.left) * 92 / 100;
|
||||
const int max_height =
|
||||
(monitor_info.rcWork.bottom - monitor_info.rcWork.top) * 92 / 100;
|
||||
if (physical_width > max_width) physical_width = max_width;
|
||||
if (physical_height > max_height) physical_height = max_height;
|
||||
}
|
||||
|
||||
HWND window = CreateWindow(
|
||||
window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
|
||||
Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
|
||||
Scale(size.width, scale_factor), Scale(size.height, scale_factor),
|
||||
nullptr, nullptr, GetModuleHandle(nullptr), this);
|
||||
physical_width, physical_height, nullptr, nullptr,
|
||||
GetModuleHandle(nullptr), this);
|
||||
|
||||
if (!window) {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user