Skip to content

Commit

Permalink
feat: 使弹窗的移动更平滑
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Oct 17, 2024
1 parent cf6ae6c commit 87b617a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Magpie.App/ToastService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,27 @@ void ToastService::ShowMessageOnWindow(std::wstring_view message, HWND hWnd) noe

// 定期更新弹窗位置
[](CoreDispatcher dispatcher, MUXC::TeachingTip teachingTip, HWND hWnd, HWND hwndToast) -> fire_and_forget {
RECT prevframeRect{};
do {
co_await 10ms;
co_await resume_background();
// 等待一帧的时间可以使弹窗的移动更平滑
DwmFlush();
co_await dispatcher;

if (!IsWindow(hwndToast)) {
break;
}

RECT frameRect;
if (!Win32Utils::GetWindowFrameRect(hWnd, frameRect)) {
break;
}

// 窗口没有移动则无需更新
if (frameRect == prevframeRect) {
continue;
}
prevframeRect = frameRect;

SetWindowPos(
hwndToast,
Expand Down
7 changes: 7 additions & 0 deletions src/Shared/Win32Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,10 @@ constexpr bool operator==(const SIZE& l, const SIZE& r) noexcept {
constexpr bool operator==(const POINT& l, const POINT& r) noexcept {
return l.x == r.x && l.y == r.y;
}

// 避免和 d3d11.h 中的定义冲突
#ifndef __d3d11_h__
constexpr bool operator==(const RECT& l, const RECT& r) noexcept {
return l.left == r.left && l.top == r.top && l.right == r.right && l.bottom == r.bottom;
}
#endif

0 comments on commit 87b617a

Please sign in to comment.