fix: 修正投屏授权状态与窗口生命周期,避免串流状态错乱
This commit is contained in:
1 parent
a0b77a3e7a
commit
4c9d006d11
6 files changed
+134
-90
No files matched your search
@@ -227,14 +227,25 @@ LRESULT VideoWindow::WndProc(HWND hwnd, UINT message, WPARAM wparam,
|
||||
case WM_SIZE:
|
||||
InvalidateRect(hwnd, nullptr, FALSE);
|
||||
return 0;
|
||||
case WM_LBUTTONDOWN:
|
||||
case WM_LBUTTONDOWN: {
|
||||
const POINT point{GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)};
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (dragging_ || !input_handler_ || !ClientToFrame(point, &x, &y)) {
|
||||
return 0;
|
||||
}
|
||||
// 画面内点击 = 在手机上点一下:先捕获鼠标,拖动时才能持续收到 WM_MOUSEMOVE。
|
||||
SetFocus(hwnd);
|
||||
SetCapture(hwnd);
|
||||
if (GetCapture() != hwnd) {
|
||||
return 0;
|
||||
}
|
||||
dragging_ = true;
|
||||
last_move_tick_ = GetTickCount64();
|
||||
DispatchPointerAt(0, POINT{GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)});
|
||||
last_touch_ = POINT{x, y};
|
||||
input_handler_(0, x, y);
|
||||
return 0;
|
||||
}
|
||||
case WM_MOUSEMOVE: {
|
||||
// 只有按住左键才下发移动(悬停不注入),并做 60Hz 限流。
|
||||
if (!dragging_) {
|
||||
@@ -253,19 +264,15 @@ LRESULT VideoWindow::WndProc(HWND hwnd, UINT message, WPARAM wparam,
|
||||
return 0;
|
||||
}
|
||||
// 先清标志再 ReleaseCapture:否则 WM_CAPTURECHANGED 会补发一次取消。
|
||||
dragging_ = false;
|
||||
ReleaseCapture();
|
||||
DispatchPointerAt(1, POINT{GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)});
|
||||
EndDrag(hwnd, 1, POINT{GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)});
|
||||
return 0;
|
||||
}
|
||||
case WM_CAPTURECHANGED: {
|
||||
case WM_CANCELMODE:
|
||||
case WM_KILLFOCUS:
|
||||
case WM_CAPTURECHANGED:
|
||||
// 窗口失焦、被别处抢走鼠标:补一个 cancel,避免手机上残留按下的手指。
|
||||
if (dragging_) {
|
||||
dragging_ = false;
|
||||
DispatchPointerAt(3, last_point_);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
EndDrag(hwnd, 3, POINT{});
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
case WM_RBUTTONUP:
|
||||
case WM_MBUTTONDOWN:
|
||||
@@ -319,6 +326,7 @@ LRESULT VideoWindow::WndProc(HWND hwnd, UINT message, WPARAM wparam,
|
||||
DestroyWindow(hwnd);
|
||||
return 0;
|
||||
case WM_DESTROY: {
|
||||
EndDrag(hwnd, 3, POINT{});
|
||||
hwnd_ = nullptr;
|
||||
open_.store(false);
|
||||
repaint_pending_.store(false);
|
||||
@@ -493,21 +501,36 @@ bool VideoWindow::ClientToFrame(POINT point, int* x, int* y) const {
|
||||
}
|
||||
|
||||
void VideoWindow::DispatchPointerAt(int action, POINT point) {
|
||||
last_point_ = point;
|
||||
InputHandler handler = input_handler_;
|
||||
if (!handler) {
|
||||
return;
|
||||
}
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (!ClientToFrame(point, &x, &y)) {
|
||||
// 已开始的拖动可以越过画面边缘。画面暂时不可用时,抬起仍用最后的触点。
|
||||
if (action != 3 && image_rect_.left < image_rect_.right &&
|
||||
image_rect_.top < image_rect_.bottom) {
|
||||
point.x = std::clamp(point.x, image_rect_.left, image_rect_.right - 1);
|
||||
point.y = std::clamp(point.y, image_rect_.top, image_rect_.bottom - 1);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (ClientToFrame(point, &x, &y)) {
|
||||
last_touch_ = POINT{x, y};
|
||||
}
|
||||
}
|
||||
handler(action, last_touch_.x, last_touch_.y);
|
||||
}
|
||||
|
||||
void VideoWindow::EndDrag(HWND hwnd, int action, POINT point) {
|
||||
if (!dragging_) {
|
||||
return;
|
||||
}
|
||||
handler(action, x, y);
|
||||
dragging_ = false;
|
||||
if (GetCapture() == hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
DispatchPointerAt(action, point);
|
||||
}
|
||||
|
||||
void VideoWindow::DispatchMouseButtonAt(int button, int action, POINT point) {
|
||||
last_point_ = point;
|
||||
MouseButtonHandler handler = mouse_button_handler_;
|
||||
if (!handler) {
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user