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:
1 parent
5f9fe88e37
commit
85e53f64ca
6 files changed
+345
-2
No files matched your search
@@ -855,6 +855,52 @@ class VideoTexturePlugin : public flutter::Plugin {
|
||||
std::make_unique<flutter::EncodableValue>(map));
|
||||
});
|
||||
|
||||
// 右键/中键:button 1=右键 2=中键,Dart 侧映射成 Android 返回/多任务。
|
||||
video_window_.SetMouseButtonHandler(
|
||||
[this](int button, int action, int x, int y) {
|
||||
if (channel_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
flutter::EncodableMap map;
|
||||
map[flutter::EncodableValue("button")] =
|
||||
flutter::EncodableValue(button);
|
||||
map[flutter::EncodableValue("action")] =
|
||||
flutter::EncodableValue(action);
|
||||
map[flutter::EncodableValue("x")] = flutter::EncodableValue(x);
|
||||
map[flutter::EncodableValue("y")] = flutter::EncodableValue(y);
|
||||
channel_->InvokeMethod("mouse",
|
||||
std::make_unique<flutter::EncodableValue>(map));
|
||||
});
|
||||
|
||||
// 滚轮:没有指针坐标,被控端用屏幕中心兜底。
|
||||
video_window_.SetWheelHandler([this](int delta_x, int delta_y) {
|
||||
if (channel_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
flutter::EncodableMap map;
|
||||
map[flutter::EncodableValue("deltaX")] =
|
||||
flutter::EncodableValue(delta_x);
|
||||
map[flutter::EncodableValue("deltaY")] =
|
||||
flutter::EncodableValue(delta_y);
|
||||
channel_->InvokeMethod("wheel",
|
||||
std::make_unique<flutter::EncodableValue>(map));
|
||||
});
|
||||
|
||||
// 键盘:只报 Windows 虚拟键码,Android keycode 的映射留在 Dart 侧。
|
||||
video_window_.SetKeyboardHandler([this](int action, int vk,
|
||||
int modifiers) {
|
||||
if (channel_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
flutter::EncodableMap map;
|
||||
map[flutter::EncodableValue("action")] = flutter::EncodableValue(action);
|
||||
map[flutter::EncodableValue("vk")] = flutter::EncodableValue(vk);
|
||||
map[flutter::EncodableValue("modifiers")] =
|
||||
flutter::EncodableValue(modifiers);
|
||||
channel_->InvokeMethod("key",
|
||||
std::make_unique<flutter::EncodableValue>(map));
|
||||
});
|
||||
|
||||
worker_ = std::thread([this, shared_frames]() { RunWorker(shared_frames); });
|
||||
}
|
||||
|
||||
@@ -862,6 +908,9 @@ class VideoTexturePlugin : public flutter::Plugin {
|
||||
// 先摘掉回调,避免析构期间 DestroyWindow 触发 InvokeMethod。
|
||||
video_window_.SetCloseHandler(nullptr);
|
||||
video_window_.SetInputHandler(nullptr);
|
||||
video_window_.SetMouseButtonHandler(nullptr);
|
||||
video_window_.SetWheelHandler(nullptr);
|
||||
video_window_.SetKeyboardHandler(nullptr);
|
||||
video_window_.Close();
|
||||
stop_.store(true);
|
||||
if (worker_.joinable()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -27,6 +27,14 @@ class VideoWindow {
|
||||
// 画面内鼠标操作回调,坐标已换算成画面像素(0..frame_width-1)。
|
||||
// action:0=按下 1=抬起 2=移动 3=取消,语义与协议 TouchEvent.action 一致。
|
||||
using InputHandler = std::function<void(int action, int x, int y)>;
|
||||
// 右键/中键回调。button:1=右键 2=中键;action:0=按下 1=抬起;
|
||||
// 坐标已换算成画面像素(黑边上的点击会被丢弃)。
|
||||
using MouseButtonHandler = std::function<void(int button, int action, int x, int y)>;
|
||||
// 滚轮回调。deltaY 正=向下滚(手指上滑),与协议 WheelEvent 的约定一致。
|
||||
using WheelHandler = std::function<void(int deltaX, int deltaY)>;
|
||||
// 键盘回调。action:0=按下 1=抬起;vk 是 Windows 虚拟键码(由 Dart 侧映射成
|
||||
// Android keycode);modifiers:bit0=ctrl bit1=alt bit2=shift bit3=meta。
|
||||
using KeyboardHandler = std::function<void(int action, int vk, int modifiers)>;
|
||||
|
||||
VideoWindow();
|
||||
~VideoWindow();
|
||||
@@ -48,6 +56,15 @@ class VideoWindow {
|
||||
// 设置/清除画面鼠标回调;传 nullptr 清除。
|
||||
void SetInputHandler(InputHandler handler);
|
||||
|
||||
// 设置/清除右键/中键回调;传 nullptr 清除。
|
||||
void SetMouseButtonHandler(MouseButtonHandler handler);
|
||||
|
||||
// 设置/清除滚轮回调;传 nullptr 清除。
|
||||
void SetWheelHandler(WheelHandler handler);
|
||||
|
||||
// 设置/清除键盘回调;传 nullptr 清除。
|
||||
void SetKeyboardHandler(KeyboardHandler handler);
|
||||
|
||||
bool IsOpen() const { return open_.load(); }
|
||||
|
||||
private:
|
||||
@@ -62,6 +79,10 @@ class VideoWindow {
|
||||
// 客户区坐标 -> 画面像素;返回 false 表示点在黑边上或还没有画面。
|
||||
bool ClientToFrame(POINT point, int* x, int* y) const;
|
||||
void DispatchPointerAt(int action, POINT point);
|
||||
void DispatchMouseButtonAt(int button, int action, POINT point);
|
||||
void DispatchKey(int action, int vk);
|
||||
// 当前修饰键状态(按协议位定义拼装)。
|
||||
int CurrentModifiers() const;
|
||||
// 离屏缓冲:整帧画完再一次性贴到窗口,避免「已填黑、还没拉伸」的中间态被合成。
|
||||
void EnsureBackBuffer(HDC reference, int width, int height);
|
||||
void ReleaseBackBuffer();
|
||||
@@ -72,6 +93,9 @@ class VideoWindow {
|
||||
FrameProvider provider_;
|
||||
CloseHandler close_handler_;
|
||||
InputHandler input_handler_;
|
||||
MouseButtonHandler mouse_button_handler_;
|
||||
WheelHandler wheel_handler_;
|
||||
KeyboardHandler keyboard_handler_;
|
||||
|
||||
// 双缓冲用的内存 DC 与位图,尺寸跟随客户区。只在窗口线程读写。
|
||||
HDC back_dc_ = nullptr;
|
||||
|
||||
Reference in new issue
Block a user