feat(sender): 串流窗口支持点击与拖拽控制

- video_window 增加 InputHandler 回调,WM_LBUTTONDOWN/MOUSEMOVE/LBUTTONUP/CAPTURECHANGED
  映射为 0/2/1/3,移动事件按 60Hz 限流
- Paint 记录帧尺寸与实际绘制矩形,ClientToFrame 换算到画面像素并过滤黑边
- video_texture 通过方法通道转发 pointer 事件到 Dart,析构时清空回调
- bridge.dart 新增 onVideoPointer,main.dart 以 msg_type=0 触摸帧下发(压力 1000/0)
This commit is contained in:
tongtong committed 2026-11-27 15:06:46 +08:00
1 parent 03a5853da7
commit a102d10089
5 files changed
+166 -2

No files matched your search

+17 -2
View File
@@ -30,9 +30,24 @@ class SenderBridge {
/// 用户关掉独立串流窗口(点关闭按钮 / 按 ESC)时触发,用于停止投屏。
void Function()? onVideoWindowClosed;
/// 用户在串流窗口里点击/拖拽画面时触发:(action, x, y)。
///
/// action 与协议 TouchEvent.action 一致(0=按下 1=抬起 2=移动 3=取消),
/// x/y 是**画面像素坐标**(编码分辨率),由被控端换算成真实屏幕坐标。
void Function(int action, int x, int y)? onVideoPointer;
Future<void> _handleVideoCall(MethodCall call) async {
if (call.method == 'windowClosed') {
onVideoWindowClosed?.call();
switch (call.method) {
case 'windowClosed':
onVideoWindowClosed?.call();
case 'pointer':
final args = call.arguments;
if (args is! Map) return;
final action = (args['action'] as num?)?.toInt();
final x = (args['x'] as num?)?.toInt();
final y = (args['y'] as num?)?.toInt();
if (action == null || x == null || y == null) return;
onVideoPointer?.call(action, x, y);
}
}
+18
View File
@@ -86,6 +86,8 @@ class _HomePageState extends State<HomePage> {
_bridge = SenderBridge(nativeCore: _nativeCore);
// 独立窗口被用户关闭 → 停止投屏。
_bridge.onVideoWindowClosed = _onStreamWindowClosed;
// 串流窗口里的鼠标点击/拖拽 → 触摸控制帧。
_bridge.onVideoPointer = _onVideoPointer;
_diagnosticLog.start();
_diagnosticLog.write('app initialized; nativeError=${_nativeError ?? '-'}');
_bridge.watchPhase().listen((phase) {
@@ -265,6 +267,22 @@ class _HomePageState extends State<HomePage> {
}
}
/// 串流窗口里的鼠标事件 → 触摸控制帧。
///
/// 坐标是画面像素(与编码分辨率一致),被控端会按「画面尺寸 → 真实屏幕尺寸」
/// 换算后再注入,因此主控端不需要知道手机的真实分辨率。
void _onVideoPointer(int action, int x, int y) {
if (!_phase.isConnected) return;
_sendControl('touch', {
'action': action,
'pointerId': 1,
'x': x,
'y': y,
// 按下/拖动保持满压力,抬起与取消归零。
'pressure': (action == 0 || action == 2) ? 1000 : 0,
});
}
void _snack(String message) {
if (!mounted) return;
ScaffoldMessenger.of(context)