feat(sender): 串流窗口补齐键盘/右键/滚轮与双向剪贴板同步

- video_window 处理右/中键(WM_RBUTTON/MBUTTON)与滚轮(WM_MOUSEWHEEL),
  并通过 ttstd/video 的 mouse / wheel 方法通道交给 Dart
- 键盘走 WM_KEYDOWN/UP 报 Windows 虚拟键码,Dart 侧映射成 Android keycode;
  Esc 仍保留为关窗,Alt 组合键旁路转发不吞掉
- 右键→返回、中键→多任务(buttons 位 bit1/bit2),滚轮按「deltaY 正=向下滚」取反
- 本机剪贴板每 700ms 轮询比较后下发 msg_type=4,被控端上行内容写入本机剪贴板;
  两端都记住最近一次同步的文本,避免来回回送
- 控制栏「发送剪贴板」改为读取本机剪贴板实时内容(原先发的是固定占位字符串)
This commit is contained in:
tongtong committed 2026-11-27 17:58:58 +08:00
1 parent 5f9fe88e37
commit 85e53f64ca
6 files changed
+345 -2

No files matched your search

@@ -150,6 +150,18 @@ void VideoWindow::SetInputHandler(InputHandler handler) {
input_handler_ = std::move(handler);
}
void VideoWindow::SetMouseButtonHandler(MouseButtonHandler handler) {
mouse_button_handler_ = std::move(handler);
}
void VideoWindow::SetWheelHandler(WheelHandler handler) {
wheel_handler_ = std::move(handler);
}
void VideoWindow::SetKeyboardHandler(KeyboardHandler handler) {
keyboard_handler_ = std::move(handler);
}
void VideoWindow::OnFrameAvailable() {
if (!open_.load()) {
return;
@@ -254,12 +266,54 @@ LRESULT VideoWindow::WndProc(HWND hwnd, UINT message, WPARAM wparam,
}
return 0;
}
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP: {
// 右键 = 手机上的「返回」,中键 = 「多任务」(映射在 Dart 侧做,这里只报按键)。
const bool right = message == WM_RBUTTONDOWN || message == WM_RBUTTONUP;
const bool down = message == WM_RBUTTONDOWN || message == WM_MBUTTONDOWN;
// 右键拖动时不想选中画面,按下前先抢焦点。
if (down) {
SetFocus(hwnd);
}
DispatchMouseButtonAt(right ? 1 : 2, down ? 0 : 1,
POINT{GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam)});
return 0;
}
case WM_MOUSEWHEEL: {
// 一格 = WHEEL_DELTA(120)。Win32 正数表示向前滚(看到更早的内容),
// 协议里 deltaY 正数表示「向下滚」(手指上滑,看到更后面的内容),所以取反。
const int steps = -GET_WHEEL_DELTA_WPARAM(wparam) / WHEEL_DELTA;
if (steps == 0) {
return 0;
}
WheelHandler handler = wheel_handler_;
if (handler) {
handler(0, steps);
}
return 0;
}
case WM_KEYDOWN:
if (wparam == VK_ESCAPE) {
// 关窗即停止投屏(由 close_handler_ 通知 Flutter)。
SendMessageW(hwnd, WM_CLOSE, 0, 0);
return 0;
}
DispatchKey(0, static_cast<int>(wparam));
return 0;
case WM_KEYUP:
DispatchKey(1, static_cast<int>(wparam));
return 0;
case WM_SYSKEYDOWN:
// Alt 组合键(Alt+F4 关窗等)仍要交给系统,先转发一份再放行。
if (wparam == VK_F4) {
break;
}
DispatchKey(0, static_cast<int>(wparam));
break;
case WM_SYSKEYUP:
DispatchKey(1, static_cast<int>(wparam));
break;
case WM_CLOSE:
DestroyWindow(hwnd);
@@ -452,6 +506,45 @@ void VideoWindow::DispatchPointerAt(int action, POINT point) {
handler(action, x, y);
}
void VideoWindow::DispatchMouseButtonAt(int button, int action, POINT point) {
last_point_ = point;
MouseButtonHandler handler = mouse_button_handler_;
if (!handler) {
return;
}
int x = 0;
int y = 0;
if (!ClientToFrame(point, &x, &y)) {
return;
}
handler(button, action, x, y);
}
void VideoWindow::DispatchKey(int action, int vk) {
KeyboardHandler handler = keyboard_handler_;
if (!handler) {
return;
}
handler(action, vk, CurrentModifiers());
}
int VideoWindow::CurrentModifiers() const {
int modifiers = 0;
if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) {
modifiers |= 0x01;
}
if ((GetKeyState(VK_MENU) & 0x8000) != 0) {
modifiers |= 0x02;
}
if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) {
modifiers |= 0x04;
}
if (((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x8000) != 0) {
modifiers |= 0x08;
}
return modifiers;
}
void VideoWindow::ApplyAspectToWindow(double aspect) {
if (hwnd_ == nullptr || aspect <= 0.0) {
return;