feat: 工具栏支持最小化源窗口

This commit is contained in:
Xu 2025-08-06 23:13:21 +08:00
commit 07a6dc2c62
5 changed files with 31 additions and 5 deletions

View file

@ -139,7 +139,7 @@ struct serializer<
namespace Magpie {
// 缓存版本号。当缓存文件结构有更改时更新它,使旧缓存失效
static constexpr uint32_t FONTS_CACHE_VERSION = 4;
static constexpr uint32_t FONTS_CACHE_VERSION = 5;
static std::wstring GetCacheFileName(const std::wstring_view& language, uint32_t dpi) noexcept {
return fmt::format(L"{}\\fonts_{}_{}", CommonSharedConstants::CACHE_DIR, language, dpi);

View file

@ -653,6 +653,8 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
_lastToolbarAlpha = _CalcToolbarAlpha();
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, _lastToolbarAlpha);
ImGui::PushStyleColor(ImGuiCol_WindowBg, (ImU32)ImColor(15, 15, 15, 180));
const ImVec2 originalWindowPadding = ImGui::GetStyle().WindowPadding;
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 6 * _dpiScale,0.0f });
_isToolbarItemActive = false;
@ -677,6 +679,7 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
ImGui::SetCursorPosY((CORNER_ROUNDING + 3) * _dpiScale);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, originalWindowPadding);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, { 4 * _dpiScale,4 * _dpiScale });
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 4 * _dpiScale);
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0);
@ -814,7 +817,23 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
ImGui::SameLine();
ImGui::SetCursorPosY((CORNER_ROUNDING + 3) * _dpiScale);
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - 50 * _dpiScale);
// 源窗口支持最小化时才显示最小化按钮
const HWND hwndSrc = ScalingWindow::Get().SrcTracker().Handle();
const bool canSrcMinimized = GetWindowStyle(hwndSrc) & WS_MINIMIZEBOX;
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x -
((canSrcMinimized ? 3 : 2) * 28 - 4) * _dpiScale);
if (canSrcMinimized) {
const std::string& minimizeStr = _GetResourceString(L"Overlay_Toolbar_Minimize");
if (drawButton(OverlayHelper::SegoeIcons::CheckboxIndeterminate, minimizeStr.c_str())) {
// 模拟通过标题栏最小化,失败则回落到 ShowWindow
if (!PostMessage(hwndSrc, WM_SYSCOMMAND, SC_MINIMIZE, 0)) {
ShowWindowAsync(hwndSrc, SW_SHOWMINIMIZED);
}
}
ImGui::SameLine();
}
{
const bool isWindowedMode = ScalingWindow::Get().Options().IsWindowedMode();
@ -828,7 +847,6 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
});
}
}
ImGui::SameLine();
// 和主窗口保持一致 (#C42B1C)
@ -854,14 +872,14 @@ bool OverlayDrawer::_DrawToolbar(uint32_t fps) noexcept {
ImGui::EndDisabled();
ImGui::PopStyleColor(5);
ImGui::PopStyleVar(5);
ImGui::PopStyleVar(6);
} else {
_isCursorOnCaptionArea = false;
}
ImGui::End();
ImGui::PopStyleColor();
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
return needRedraw;
}

View file

@ -53,6 +53,7 @@ struct OverlayHelper {
static const ImWchar Cancel = 0xE711;
static const ImWchar Camera = 0xE722;
static const ImWchar Favicon = 0xE737;
static const ImWchar CheckboxIndeterminate = 0xE73C;
static const ImWchar FullScreen = 0xE740;
static const ImWchar Pinned = 0xE840;
static const ImWchar Diagnostic = 0xE9D9;
@ -65,6 +66,7 @@ struct OverlayHelper {
SegoeIcons::Cancel, SegoeIcons::Cancel,
SegoeIcons::Camera, SegoeIcons::Camera,
SegoeIcons::Favicon, SegoeIcons::Favicon,
SegoeIcons::CheckboxIndeterminate, SegoeIcons::CheckboxIndeterminate,
SegoeIcons::FullScreen, SegoeIcons::FullScreen,
SegoeIcons::Pinned, SegoeIcons::Pinned,
SegoeIcons::Diagnostic, SegoeIcons::Diagnostic,

View file

@ -1015,4 +1015,7 @@
<data name="NotifyIcon_Timer_Windowed" xml:space="preserve">
<value>Scale after {}s (Windowed)</value>
</data>
<data name="Overlay_Toolbar_Minimize" xml:space="preserve">
<value>Minimize</value>
</data>
</root>

View file

@ -1015,4 +1015,7 @@
<data name="NotifyIcon_Timer_Windowed" xml:space="preserve">
<value>{} 秒后缩放 (窗口模式)</value>
</data>
<data name="Overlay_Toolbar_Minimize" xml:space="preserve">
<value>最小化</value>
</data>
</root>