flutter_desktop: remote window cursor debug

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-08-13 17:58:24 +08:00
parent af2e555e41
commit fd8c83497d

View File

@ -41,6 +41,7 @@ class _RemotePageState extends State<RemotePage>
String _value = ''; String _value = '';
double _scale = 1; double _scale = 1;
double _mouseScrollIntegral = 0; // mouse scroll speed controller double _mouseScrollIntegral = 0; // mouse scroll speed controller
var _cursorOverImage = false.obs;
var _more = true; var _more = true;
var _fn = false; var _fn = false;
@ -291,62 +292,7 @@ class _RemotePageState extends State<RemotePage>
} }
Widget getRawPointerAndKeyBody(Widget child) { Widget getRawPointerAndKeyBody(Widget child) {
return Listener( return Consumer<FfiModel>(
onPointerHover: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (!_isPhysicalMouse) {
setState(() {
_isPhysicalMouse = true;
});
}
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousemove'),
tabBarHeight: super.widget.tabBarHeight);
}
},
onPointerDown: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) {
if (_isPhysicalMouse) {
setState(() {
_isPhysicalMouse = false;
});
}
}
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousedown'),
tabBarHeight: super.widget.tabBarHeight);
}
},
onPointerUp: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mouseup'),
tabBarHeight: super.widget.tabBarHeight);
}
},
onPointerMove: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousemove'),
tabBarHeight: super.widget.tabBarHeight);
}
},
onPointerSignal: (e) {
if (e is PointerScrollEvent) {
var dx = e.scrollDelta.dx;
var dy = e.scrollDelta.dy;
if (dx > 0)
dx = -1;
else if (dx < 0) dx = 1;
if (dy > 0)
dy = -1;
else if (dy < 0) dy = 1;
bind.sessionSendMouse(
id: widget.id,
msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
}
},
child: Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion( builder: (context, FfiModel, _child) => MouseRegion(
cursor: FfiModel.permissions['keyboard'] != false cursor: FfiModel.permissions['keyboard'] != false
? SystemMouseCursors.none ? SystemMouseCursors.none
@ -394,11 +340,13 @@ class _RemotePageState extends State<RemotePage>
} }
return KeyEventResult.handled; return KeyEventResult.handled;
}, },
child: child))))); child: child))));
} }
Widget? getBottomAppBar() { Widget? getBottomAppBar() {
return BottomAppBar( return MouseRegion(
cursor: SystemMouseCursors.basic,
child: BottomAppBar(
elevation: 10, elevation: 10,
color: MyTheme.accent, color: MyTheme.accent,
child: Row( child: Row(
@ -498,6 +446,81 @@ class _RemotePageState extends State<RemotePage>
/// DoubleFiner -> right click /// DoubleFiner -> right click
/// HoldDrag -> left drag /// HoldDrag -> left drag
void _onPointHoverImage(PointerHoverEvent e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (!_isPhysicalMouse) {
setState(() {
_isPhysicalMouse = true;
});
}
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousemove'),
tabBarHeight: super.widget.tabBarHeight);
}
}
void _onPointDownImage(PointerDownEvent e) {
if (e.kind != ui.PointerDeviceKind.mouse) {
if (_isPhysicalMouse) {
setState(() {
_isPhysicalMouse = false;
});
}
}
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousedown'),
tabBarHeight: super.widget.tabBarHeight);
}
}
void _onPointUpImage(PointerUpEvent e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mouseup'),
tabBarHeight: super.widget.tabBarHeight);
}
}
void _onPointMoveImage(PointerMoveEvent e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
if (_isPhysicalMouse) {
_ffi.handleMouse(getEvent(e, 'mousemove'),
tabBarHeight: super.widget.tabBarHeight);
}
}
void _onPointerSignalImage(PointerSignalEvent e) {
if (e is PointerScrollEvent) {
var dx = e.scrollDelta.dx;
var dy = e.scrollDelta.dy;
if (dx > 0)
dx = -1;
else if (dx < 0) dx = 1;
if (dy > 0)
dy = -1;
else if (dy < 0) dy = 1;
bind.sessionSendMouse(
id: widget.id, msg: '{"type": "wheel", "x": "$dx", "y": "$dy"}');
}
}
Widget _buildImageListener(Widget child) {
return Listener(
onPointerHover: _onPointHoverImage,
onPointerDown: _onPointDownImage,
onPointerUp: _onPointUpImage,
onPointerMove: _onPointMoveImage,
onPointerSignal: _onPointerSignalImage,
child: MouseRegion(
onEnter: (evt) {
_cursorOverImage.value = true;
},
onExit: (evt) {
_cursorOverImage.value = false;
},
child: child));
}
Widget getBodyForDesktop(BuildContext context, bool keyboard) { Widget getBodyForDesktop(BuildContext context, bool keyboard) {
var paints = <Widget>[ var paints = <Widget>[
MouseRegion(onEnter: (evt) { MouseRegion(onEnter: (evt) {
@ -824,10 +847,17 @@ class _RemotePageState extends State<RemotePage>
class ImagePaint extends StatelessWidget { class ImagePaint extends StatelessWidget {
final String id; final String id;
final Rx<bool> cursorOverImage;
final Widget Function(Widget)? listenerBuilder;
final ScrollController _horizontal = ScrollController(); final ScrollController _horizontal = ScrollController();
final ScrollController _vertical = ScrollController(); final ScrollController _vertical = ScrollController();
ImagePaint({Key? key, required this.id}) : super(key: key); ImagePaint(
{Key? key,
required this.id,
required this.cursorOverImage,
this.listenerBuilder = null})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -835,6 +865,12 @@ class ImagePaint extends StatelessWidget {
var c = Provider.of<CanvasModel>(context); var c = Provider.of<CanvasModel>(context);
final s = c.scale; final s = c.scale;
if (c.scrollStyle == ScrollStyle.scrollbar) { if (c.scrollStyle == ScrollStyle.scrollbar) {
final imageWidget = SizedBox(
width: c.getDisplayWidth() * s,
height: c.getDisplayHeight() * s,
child: CustomPaint(
painter: new ImagePainter(image: m.image, x: 0, y: 0, scale: s),
));
return Center( return Center(
child: NotificationListener<ScrollNotification>( child: NotificationListener<ScrollNotification>(
onNotification: (_notification) { onNotification: (_notification) {
@ -849,7 +885,26 @@ class ImagePaint extends StatelessWidget {
c.setScrollPercent(percentX, percentY); c.setScrollPercent(percentX, percentY);
return false; return false;
}, },
child: Scrollbar( child: Obx(() => MouseRegion(
cursor: cursorOverImage.value
? SystemMouseCursors.none
: SystemMouseCursors.basic,
child: _buildCrossScrollbar(_buildListener(imageWidget)))),
));
} else {
final imageWidget = SizedBox(
width: c.size.width,
height: c.size.height,
child: CustomPaint(
painter: new ImagePainter(
image: m.image, x: c.x / s, y: c.y / s, scale: s),
));
return _buildListener(imageWidget);
}
}
Widget _buildCrossScrollbar(Widget child) {
return Scrollbar(
controller: _vertical, controller: _vertical,
thumbVisibility: true, thumbVisibility: true,
trackVisibility: true, trackVisibility: true,
@ -863,47 +918,18 @@ class ImagePaint extends StatelessWidget {
child: SingleChildScrollView( child: SingleChildScrollView(
controller: _horizontal, controller: _horizontal,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
child: buildListener(SizedBox( child: child,
width: c.getDisplayWidth() * s, ),
height: c.getDisplayHeight() * s,
child: CustomPaint(
painter: new ImagePainter(
image: m.image, x: 0, y: 0, scale: s),
)))),
), ),
)),
)); ));
} else {
return buildListener(CustomPaint(
painter:
new ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
));
}
} }
Widget buildListener(Widget child) { Widget _buildListener(Widget child) {
return Listener( if (listenerBuilder != null) {
onPointerHover: (e) { return listenerBuilder!(child);
debugPrint( } else {
'REMOVE ME ======================== 4444 onPointerHover ${e.position}'); return child;
}, }
onPointerDown: (e) {
debugPrint(
'REMOVE ME ======================== 4444 onPointerDown ${e.position}');
},
onPointerUp: (e) {
debugPrint(
'REMOVE ME ======================== 4444 onPointerUp ${e.position}');
},
onPointerMove: (e) {
debugPrint(
'REMOVE ME ======================== 4444 onPointerMove ${e.position}');
},
onPointerSignal: (e) {
debugPrint(
'REMOVE ME ======================== 3333 onPointerSignal ${e.position}');
},
child: child);
} }
} }