rustdesk/flutter/lib/mobile/pages/remote_page.dart

933 lines
32 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hbb/common/shared_state.dart';
import 'package:flutter_hbb/common/widgets/toolbar.dart';
import 'package:flutter_hbb/consts.dart';
2022-05-24 23:33:00 +08:00
import 'package:flutter_hbb/mobile/widgets/gesture_help.dart';
import 'package:flutter_hbb/models/chat_model.dart';
2023-02-12 20:26:04 +08:00
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:get/get.dart';
2020-11-18 23:15:59 +08:00
import 'package:provider/provider.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
2022-05-24 23:33:00 +08:00
import '../../common.dart';
2022-09-27 23:05:11 +08:00
import '../../common/widgets/overlay.dart';
import '../../common/widgets/dialog.dart';
import '../../common/widgets/remote_input.dart';
2022-09-27 20:35:02 +08:00
import '../../models/input_model.dart';
2022-05-24 23:33:00 +08:00
import '../../models/model.dart';
2022-08-05 20:29:43 +08:00
import '../../models/platform_model.dart';
import '../../utils/image.dart';
import '../widgets/dialog.dart';
final initText = '1' * 1024;
2020-11-28 18:06:27 +08:00
class RemotePage extends StatefulWidget {
RemotePage({Key? key, required this.id, this.password, this.isSharedPassword})
: super(key: key);
final String id;
final String? password;
final bool? isSharedPassword;
@override
State<RemotePage> createState() => _RemotePageState();
}
class _RemotePageState extends State<RemotePage> {
2022-02-17 15:22:14 +08:00
Timer? _timer;
2022-05-23 16:02:37 +08:00
bool _showBar = !isWebDesktop;
bool _showGestureHelp = false;
2020-11-25 16:28:46 +08:00
String _value = '';
2022-06-02 17:16:23 +08:00
Orientation? _currentOrientation;
final _blockableOverlayState = BlockableOverlayState();
final keyboardVisibilityController = KeyboardVisibilityController();
2023-02-12 20:26:04 +08:00
late final StreamSubscription<bool> keyboardSubscription;
2022-04-25 18:25:25 +08:00
final FocusNode _mobileFocusNode = FocusNode();
final FocusNode _physicalFocusNode = FocusNode();
var _showEdit = false; // use soft keyboard
InputModel get inputModel => gFFI.inputModel;
SessionID get sessionId => gFFI.sessionId;
2022-09-27 20:35:02 +08:00
2020-11-17 11:12:55 +08:00
@override
void initState() {
super.initState();
gFFI.start(
widget.id,
password: widget.password,
isSharedPassword: widget.isSharedPassword,
);
2022-05-26 18:25:16 +08:00
WidgetsBinding.instance.addPostFrameCallback((_) {
2022-02-24 18:24:52 +08:00
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
2022-08-12 18:42:02 +08:00
gFFI.dialogManager
.showLoading(translate('Connecting...'), onCancel: closeConnection);
});
WakelockPlus.enable();
2022-04-25 18:25:25 +08:00
_physicalFocusNode.requestFocus();
gFFI.ffiModel.updateEventListener(sessionId, widget.id);
2022-09-27 20:35:02 +08:00
gFFI.inputModel.listenToMouse(true);
gFFI.qualityMonitorModel.checkShowQualityMonitor(sessionId);
2023-02-12 20:26:04 +08:00
keyboardSubscription =
keyboardVisibilityController.onChange.listen(onSoftKeyboardChanged);
initSharedStates(widget.id);
gFFI.chatModel
.changeCurrentKey(MessageKey(widget.id, ChatModel.clientModeID));
_blockableOverlayState.applyFfi(gFFI);
}
@override
2023-06-28 17:09:23 +08:00
Future<void> dispose() async {
// https://github.com/flutter/flutter/issues/64935
super.dispose();
gFFI.dialogManager.hideMobileActionsOverlay();
2022-09-27 20:35:02 +08:00
gFFI.inputModel.listenToMouse(false);
2023-06-28 17:09:23 +08:00
await gFFI.invokeMethod("enable_soft_keyboard", true);
2022-04-25 18:25:25 +08:00
_mobileFocusNode.dispose();
_physicalFocusNode.dispose();
2023-06-28 17:09:23 +08:00
await gFFI.close();
2020-11-27 16:06:35 +08:00
_timer?.cancel();
2022-08-12 18:42:02 +08:00
gFFI.dialogManager.dismissAll();
2023-06-28 17:09:23 +08:00
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
2022-02-24 18:24:52 +08:00
overlays: SystemUiOverlay.values);
await WakelockPlus.disable();
2023-06-28 17:09:23 +08:00
await keyboardSubscription.cancel();
removeSharedStates(widget.id);
}
// to-do: It should be better to use transparent color instead of the bgColor.
// But for now, the transparent color will cause the canvas to be white.
// I'm sure that the white color is caused by the Overlay widget in BlockableOverlay.
// But I don't know why and how to fix it.
Widget emptyOverlay(Color bgColor) => BlockableOverlay(
/// the Overlay key will be set with _blockableOverlayState in BlockableOverlay
/// see override build() in [BlockableOverlay]
state: _blockableOverlayState,
underlying: Container(
color: bgColor,
),
);
2023-02-12 20:26:04 +08:00
void onSoftKeyboardChanged(bool visible) {
if (!visible) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
// [pi.version.isNotEmpty] -> check ready or not, avoid login without soft-keyboard
if (gFFI.chatModel.chatWindowOverlayEntry == null &&
gFFI.ffiModel.pi.version.isNotEmpty) {
gFFI.invokeMethod("enable_soft_keyboard", false);
}
} else {
_timer?.cancel();
_timer = Timer(kMobileDelaySoftKeyboardFocus, () {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
_mobileFocusNode.requestFocus();
});
}
2023-02-12 21:03:43 +08:00
// update for Scaffold
setState(() {});
2020-11-19 21:59:49 +08:00
}
2022-04-25 18:25:25 +08:00
// handle mobile virtual keyboard
2022-09-27 23:05:11 +08:00
void handleSoftKeyboardInput(String newValue) {
2021-08-17 22:57:35 +08:00
var oldValue = _value;
_value = newValue;
2022-01-25 18:13:11 +08:00
if (isIOS) {
2021-08-17 22:57:35 +08:00
var i = newValue.length - 1;
for (; i >= 0 && newValue[i] != '\1'; --i) {}
var j = oldValue.length - 1;
for (; j >= 0 && oldValue[j] != '\1'; --j) {}
if (i < j) j = i;
newValue = newValue.substring(j + 1);
oldValue = oldValue.substring(j + 1);
var common = 0;
for (;
common < oldValue.length &&
common < newValue.length &&
newValue[common] == oldValue[common];
++common) {}
2021-08-17 22:57:35 +08:00
for (i = 0; i < oldValue.length - common; ++i) {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_BACK');
2021-08-17 22:57:35 +08:00
}
if (newValue.length > common) {
var s = newValue.substring(common);
if (s.length > 1) {
bind.sessionInputString(sessionId: sessionId, value: s);
2021-08-17 22:57:35 +08:00
} else {
inputChar(s);
}
}
return;
}
if (oldValue.isNotEmpty &&
newValue.isNotEmpty &&
2021-08-17 22:57:35 +08:00
oldValue[0] == '\1' &&
newValue[0] != '\1') {
2020-11-28 18:06:27 +08:00
// clipboard
2021-08-17 22:57:35 +08:00
oldValue = '';
2020-11-28 18:06:27 +08:00
}
if (newValue.length == oldValue.length) {
// ?
} else if (newValue.length < oldValue.length) {
2020-11-28 18:06:27 +08:00
final char = 'VK_BACK';
2022-09-27 20:35:02 +08:00
inputModel.inputKey(char);
2020-11-28 18:06:27 +08:00
} else {
2021-08-17 22:57:35 +08:00
final content = newValue.substring(oldValue.length);
2020-11-28 18:06:27 +08:00
if (content.length > 1) {
2021-08-17 22:57:35 +08:00
if (oldValue != '' &&
2020-12-22 16:00:10 +08:00
content.length == 2 &&
(content == '""' ||
content == '()' ||
content == '[]' ||
content == '<>' ||
content == "{}" ||
content == '”“' ||
content == '《》' ||
content == '' ||
content == '【】')) {
2020-12-22 16:07:48 +08:00
// can not only input content[0], because when input ], [ are also auo insert, which cause ] never be input
bind.sessionInputString(sessionId: sessionId, value: content);
2020-12-22 16:00:10 +08:00
openKeyboard();
return;
}
bind.sessionInputString(sessionId: sessionId, value: content);
2020-11-28 18:06:27 +08:00
} else {
2021-08-17 22:57:35 +08:00
inputChar(content);
2020-11-28 18:06:27 +08:00
}
}
2021-08-17 22:57:35 +08:00
}
void inputChar(String char) {
if (char == '\n') {
char = 'VK_RETURN';
} else if (char == ' ') {
char = 'VK_SPACE';
}
2022-09-27 20:35:02 +08:00
inputModel.inputKey(char);
2020-11-28 18:06:27 +08:00
}
void openKeyboard() {
gFFI.invokeMethod("enable_soft_keyboard", true);
2020-11-28 18:06:27 +08:00
// destroy first, so that our _value trick can work
2020-12-22 15:26:35 +08:00
_value = initText;
setState(() => _showEdit = false);
2020-11-28 18:06:27 +08:00
_timer?.cancel();
_timer = Timer(kMobileDelaySoftKeyboard, () {
2020-11-28 18:06:27 +08:00
// show now, and sleep a while to requestFocus to
// make sure edit ready, so that keyboard wont show/hide/show/hide happen
setState(() => _showEdit = true);
2020-11-28 18:06:27 +08:00
_timer?.cancel();
_timer = Timer(kMobileDelaySoftKeyboardFocus, () {
2022-02-24 18:24:52 +08:00
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
2022-04-25 18:25:25 +08:00
_mobileFocusNode.requestFocus();
2020-11-28 18:06:27 +08:00
});
});
}
bool get keyboard => gFFI.ffiModel.permissions['keyboard'] != false;
Widget _bottomWidget() => _showGestureHelp
? getGestureHelp()
: (_showBar && gFFI.ffiModel.pi.displays.isNotEmpty
? getBottomAppBar(keyboard)
: Offstage());
@override
Widget build(BuildContext context) {
final keyboardIsVisible =
2023-02-12 20:26:04 +08:00
keyboardVisibilityController.isVisible && _showEdit;
final showActionButton = !_showBar || keyboardIsVisible || _showGestureHelp;
2020-11-22 18:29:04 +08:00
return WillPopScope(
onWillPop: () async {
clientClose(sessionId, gFFI.dialogManager);
return false;
},
child: Scaffold(
// workaround for https://github.com/rustdesk/rustdesk/issues/3131
floatingActionButtonLocation: keyboardIsVisible
? FABLocation(FloatingActionButtonLocation.endFloat, 0, -35)
: null,
floatingActionButton: !showActionButton
? null
: FloatingActionButton(
mini: !keyboardIsVisible,
child: Icon(
(keyboardIsVisible || _showGestureHelp)
? Icons.expand_more
: Icons.expand_less,
color: Colors.white,
),
backgroundColor: MyTheme.accent,
onPressed: () {
setState(() {
if (keyboardIsVisible) {
_showEdit = false;
gFFI.invokeMethod("enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
_physicalFocusNode.requestFocus();
} else if (_showGestureHelp) {
_showGestureHelp = false;
} else {
_showBar = !_showBar;
}
});
}),
bottomNavigationBar: Obx(() => Stack(
alignment: Alignment.bottomCenter,
children: [
gFFI.ffiModel.pi.isSet.isTrue &&
gFFI.ffiModel.waitForFirstImage.isTrue
? emptyOverlay(MyTheme.canvasColor)
: () {
gFFI.ffiModel.tryShowAndroidActionsOverlay();
return Offstage();
}(),
_bottomWidget(),
gFFI.ffiModel.pi.isSet.isFalse
? emptyOverlay(MyTheme.canvasColor)
: Offstage(),
],
)),
body: getRawPointerAndKeyBody(Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
return Container(
color: Colors.black,
child: isWebDesktop
? getBodyForDesktopWithListener(keyboard)
: SafeArea(child:
OrientationBuilder(builder: (ctx, orientation) {
if (_currentOrientation != orientation) {
Timer(const Duration(milliseconds: 200), () {
gFFI.dialogManager
.resetMobileActionsOverlay(ffi: gFFI);
_currentOrientation = orientation;
gFFI.canvasModel.updateViewStyle();
});
}
return Obx(
() => Container(
color: MyTheme.canvasColor,
child: inputModel.isPhysicalMouse.value
? getBodyForMobile()
: RawTouchGestureDetectorRegion(
child: getBodyForMobile(),
ffi: gFFI,
),
),
);
})));
})
],
))),
);
2020-11-20 16:37:48 +08:00
}
Widget getRawPointerAndKeyBody(Widget child) {
final keyboard = gFFI.ffiModel.permissions['keyboard'] != false;
return RawPointerMouseRegion(
cursor: keyboard ? SystemMouseCursors.none : MouseCursor.defer,
inputModel: inputModel,
// Disable RawKeyFocusScope before the connecting is established.
// The "Delete" key on the soft keyboard may be grabbed when inputting the password dialog.
child: gFFI.ffiModel.pi.isSet.isTrue
? RawKeyFocusScope(
focusNode: _physicalFocusNode,
inputModel: inputModel,
child: child)
: child,
);
2022-04-25 18:25:25 +08:00
}
Widget getBottomAppBar(bool keyboard) {
2022-02-02 01:20:14 +08:00
return BottomAppBar(
elevation: 10,
color: MyTheme.accent,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
IconButton(
color: Colors.white,
icon: Icon(Icons.clear),
onPressed: () {
clientClose(sessionId, gFFI.dialogManager);
},
)
] +
2022-02-02 01:20:14 +08:00
<Widget>[
IconButton(
color: Colors.white,
icon: Icon(Icons.tv),
onPressed: () {
setState(() => _showEdit = false);
showOptions(context, widget.id, gFFI.dialogManager);
2022-02-02 01:20:14 +08:00
},
)
] +
2022-05-23 16:02:37 +08:00
(isWebDesktop
2022-02-02 01:20:14 +08:00
? []
: gFFI.ffiModel.isPeerAndroid
? [
2023-10-17 22:12:52 +08:00
IconButton(
color: Colors.white,
icon: Icon(Icons.keyboard),
onPressed: openKeyboard),
IconButton(
color: Colors.white,
icon: const Icon(Icons.build),
onPressed: () => gFFI.dialogManager
.toggleMobileActionsOverlay(ffi: gFFI),
)
]
: [
IconButton(
color: Colors.white,
icon: Icon(Icons.keyboard),
onPressed: openKeyboard),
IconButton(
color: Colors.white,
icon: Icon(gFFI.ffiModel.touchMode
? Icons.touch_app
: Icons.mouse),
onPressed: () => setState(
() => _showGestureHelp = !_showGestureHelp),
),
]) +
2022-03-28 00:36:53 +08:00
(isWeb
? []
: <Widget>[
IconButton(
color: Colors.white,
icon: Icon(Icons.message),
onPressed: () {
gFFI.chatModel.changeCurrentKey(MessageKey(
widget.id, ChatModel.clientModeID));
2022-08-11 10:19:12 +08:00
gFFI.chatModel.toggleChatOverlay();
},
)
]) +
2022-03-28 00:36:53 +08:00
[
2022-02-02 01:20:14 +08:00
IconButton(
color: Colors.white,
icon: Icon(Icons.more_vert),
onPressed: () {
setState(() => _showEdit = false);
2022-08-05 20:29:43 +08:00
showActions(widget.id);
2022-02-02 01:20:14 +08:00
},
),
]),
Obx(() => IconButton(
color: Colors.white,
icon: Icon(Icons.expand_more),
onPressed: gFFI.ffiModel.waitForFirstImage.isTrue
? null
: () {
setState(() => _showBar = !_showBar);
},
)),
2022-02-02 01:20:14 +08:00
],
),
);
}
bool get showCursorPaint =>
!gFFI.ffiModel.isPeerAndroid && !gFFI.canvasModel.cursorEmbedded;
2022-02-03 00:53:59 +08:00
Widget getBodyForMobile() {
2023-02-12 21:03:43 +08:00
final keyboardIsVisible = keyboardVisibilityController.isVisible;
2022-02-03 00:53:59 +08:00
return Container(
color: MyTheme.canvasColor,
child: Stack(children: () {
final paints = [
ImagePaint(),
Positioned(
top: 10,
right: 10,
child: QualityMonitor(gFFI.qualityMonitorModel),
),
KeyHelpTools(requestShow: (keyboardIsVisible || _showGestureHelp)),
SizedBox(
width: 0,
height: 0,
child: !_showEdit
? Container()
: TextFormField(
textInputAction: TextInputAction.newline,
autocorrect: false,
enableSuggestions: false,
autofocus: true,
focusNode: _mobileFocusNode,
maxLines: null,
initialValue: _value,
// trick way to make backspace work always
keyboardType: TextInputType.multiline,
onChanged: handleSoftKeyboardInput,
),
),
];
if (showCursorPaint) {
paints.add(CursorPaint());
}
return paints;
}()));
2022-02-03 00:53:59 +08:00
}
2022-04-25 18:25:25 +08:00
Widget getBodyForDesktopWithListener(bool keyboard) {
2022-02-06 16:29:56 +08:00
var paints = <Widget>[ImagePaint()];
if (showCursorPaint) {
final cursor = bind.sessionGetToggleOptionSync(
sessionId: sessionId, arg: 'show-remote-cursor');
if (keyboard || cursor) {
paints.add(CursorPaint());
}
2022-02-06 16:29:56 +08:00
}
2022-04-25 18:25:25 +08:00
return Container(
color: MyTheme.canvasColor, child: Stack(children: paints));
}
2022-08-05 20:29:43 +08:00
void showActions(String id) async {
2021-08-21 17:18:14 +08:00
final size = MediaQuery.of(context).size;
final x = 120.0;
final y = size.height;
final menus = toolbarControls(context, id, gFFI);
getChild(TTextMenu menu) {
if (menu.trailingIcon != null) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
menu.child,
menu.trailingIcon!,
]);
} else {
return menu.child;
}
}
final more = menus
.asMap()
.entries
.map((e) => PopupMenuItem<int>(child: getChild(e.value), value: e.key))
.toList();
() async {
var index = await showMenu(
2021-08-21 17:18:14 +08:00
context: context,
position: RelativeRect.fromLTRB(x, y, x, y),
2022-02-02 00:46:21 +08:00
items: more,
2021-08-21 17:18:14 +08:00
elevation: 8,
);
if (index != null && index < menus.length) {
menus[index].onPressed.call();
2021-08-21 17:18:14 +08:00
}
}();
}
/// aka changeTouchMode
BottomAppBar getGestureHelp() {
return BottomAppBar(
child: SingleChildScrollView(
controller: ScrollController(),
padding: EdgeInsets.symmetric(vertical: 10),
child: GestureHelp(
touchMode: gFFI.ffiModel.touchMode,
onTouchModeChange: (t) {
gFFI.ffiModel.toggleTouchMode();
final v = gFFI.ffiModel.touchMode ? 'Y' : '';
bind.sessionPeerOption(
sessionId: sessionId, name: "touch-mode", value: v);
})));
2022-02-24 15:59:03 +08:00
}
// * Currently mobile does not enable map mode
// void changePhysicalKeyboardInputMode() async {
// var current = await bind.sessionGetKeyboardMode(id: widget.id) ?? "legacy";
// gFFI.dialogManager.show((setState, close) {
// void setMode(String? v) async {
// await bind.sessionSetKeyboardMode(id: widget.id, value: v ?? "");
// setState(() => current = v ?? '');
// Future.delayed(Duration(milliseconds: 300), close);
// }
//
// return CustomAlertDialog(
// title: Text(translate('Physical Keyboard Input Mode')),
// content: Column(mainAxisSize: MainAxisSize.min, children: [
// getRadio('Legacy mode', 'legacy', current, setMode),
// getRadio('Map mode', 'map', current, setMode),
// ]));
// }, clickMaskDismiss: true);
// }
2023-02-12 21:03:43 +08:00
}
class KeyHelpTools extends StatefulWidget {
/// need to show by external request, etc [keyboardIsVisible] or [changeTouchMode]
final bool requestShow;
KeyHelpTools({required this.requestShow});
@override
State<KeyHelpTools> createState() => _KeyHelpToolsState();
}
class _KeyHelpToolsState extends State<KeyHelpTools> {
var _more = true;
var _fn = false;
var _pin = false;
final _keyboardVisibilityController = KeyboardVisibilityController();
2022-09-27 22:56:18 +08:00
2023-02-12 21:03:43 +08:00
InputModel get inputModel => gFFI.inputModel;
Widget wrap(String text, void Function() onPressed,
{bool? active, IconData? icon}) {
2023-02-12 21:03:43 +08:00
return TextButton(
style: TextButton.styleFrom(
minimumSize: Size(0, 0),
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 9.75),
//adds padding inside the button
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
//limits the touch area to the button area
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
backgroundColor: active == true ? MyTheme.accent80 : null,
),
child: icon != null
? Icon(icon, size: 14, color: Colors.white)
2023-02-12 21:03:43 +08:00
: Text(translate(text),
style: TextStyle(color: Colors.white, fontSize: 11)),
onPressed: onPressed);
}
@override
Widget build(BuildContext context) {
final hasModifierOn = inputModel.ctrl ||
inputModel.alt ||
inputModel.shift ||
inputModel.command;
if (!_pin && !hasModifierOn && !widget.requestShow) {
return Offstage();
2020-11-25 13:03:48 +08:00
}
2021-08-17 15:07:01 +08:00
final size = MediaQuery.of(context).size;
2022-09-27 20:35:02 +08:00
final pi = gFFI.ffiModel.pi;
final isMac = pi.platform == kPeerPlatformMacOS;
2020-11-25 16:28:46 +08:00
final modifiers = <Widget>[
2021-08-17 15:07:01 +08:00
wrap('Ctrl ', () {
2022-09-27 20:35:02 +08:00
setState(() => inputModel.ctrl = !inputModel.ctrl);
}, active: inputModel.ctrl),
2021-08-17 15:07:01 +08:00
wrap(' Alt ', () {
2022-09-27 20:35:02 +08:00
setState(() => inputModel.alt = !inputModel.alt);
}, active: inputModel.alt),
2020-11-25 16:28:46 +08:00
wrap('Shift', () {
2022-09-27 20:35:02 +08:00
setState(() => inputModel.shift = !inputModel.shift);
}, active: inputModel.shift),
2021-08-17 15:07:01 +08:00
wrap(isMac ? ' Cmd ' : ' Win ', () {
2022-09-27 20:35:02 +08:00
setState(() => inputModel.command = !inputModel.command);
}, active: inputModel.command),
2020-11-25 16:28:46 +08:00
];
final keys = <Widget>[
wrap(
2021-08-17 15:07:01 +08:00
' Fn ',
() => setState(
2020-11-25 16:28:46 +08:00
() {
_fn = !_fn;
if (_fn) {
_more = false;
}
},
),
active: _fn),
wrap(
'',
() => setState(
() => _pin = !_pin,
),
active: _pin,
icon: Icons.push_pin),
2020-11-25 16:28:46 +08:00
wrap(
2021-08-17 15:07:01 +08:00
' ... ',
() => setState(
2020-11-25 16:28:46 +08:00
() {
_more = !_more;
if (_more) {
_fn = false;
}
},
),
active: _more),
2020-11-25 16:28:46 +08:00
];
final fn = <Widget>[
SizedBox(width: 9999),
];
for (var i = 1; i <= 12; ++i) {
final name = 'F$i';
2020-11-25 16:28:46 +08:00
fn.add(wrap(name, () {
inputModel.inputKey('VK_$name');
2020-11-25 16:28:46 +08:00
}));
}
final more = <Widget>[
SizedBox(width: 9999),
wrap('Esc', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_ESCAPE');
2020-11-25 16:28:46 +08:00
}),
wrap('Tab', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_TAB');
2020-11-25 16:28:46 +08:00
}),
wrap('Home', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_HOME');
2020-11-25 16:28:46 +08:00
}),
wrap('End', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_END');
2020-11-25 16:28:46 +08:00
}),
wrap('Ins', () {
inputModel.inputKey('VK_INSERT');
}),
2020-11-25 16:28:46 +08:00
wrap('Del', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_DELETE');
2020-11-25 16:28:46 +08:00
}),
2020-11-27 02:14:27 +08:00
wrap('PgUp', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_PRIOR');
2020-11-25 16:28:46 +08:00
}),
2021-08-17 15:07:01 +08:00
wrap('PgDn', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_NEXT');
2020-11-25 16:28:46 +08:00
}),
SizedBox(width: 9999),
wrap('', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_LEFT');
}, icon: Icons.keyboard_arrow_left),
wrap('', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_UP');
}, icon: Icons.keyboard_arrow_up),
wrap('', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_DOWN');
}, icon: Icons.keyboard_arrow_down),
wrap('', () {
2022-09-27 20:35:02 +08:00
inputModel.inputKey('VK_RIGHT');
}, icon: Icons.keyboard_arrow_right),
2021-08-11 00:22:47 +08:00
wrap(isMac ? 'Cmd+C' : 'Ctrl+C', () {
sendPrompt(isMac, 'VK_C');
}),
2021-08-11 00:22:47 +08:00
wrap(isMac ? 'Cmd+V' : 'Ctrl+V', () {
sendPrompt(isMac, 'VK_V');
2021-08-06 22:45:45 +08:00
}),
2021-08-11 00:22:47 +08:00
wrap(isMac ? 'Cmd+S' : 'Ctrl+S', () {
sendPrompt(isMac, 'VK_S');
}),
2020-11-25 16:28:46 +08:00
];
2021-08-17 15:07:01 +08:00
final space = size.width > 320 ? 4.0 : 2.0;
2020-11-25 16:28:46 +08:00
return Container(
2020-11-27 02:14:27 +08:00
color: Color(0xAA000000),
padding: EdgeInsets.only(
top: _keyboardVisibilityController.isVisible ? 24 : 4, bottom: 8),
2020-11-25 16:28:46 +08:00
child: Wrap(
2021-08-17 15:07:01 +08:00
spacing: space,
runSpacing: space,
2020-11-25 16:28:46 +08:00
children: <Widget>[SizedBox(width: 9999)] +
2023-02-12 20:26:04 +08:00
modifiers +
keys +
(_fn ? fn : []) +
(_more ? more : []),
2020-11-25 16:28:46 +08:00
));
2020-11-25 13:03:48 +08:00
}
2020-11-17 11:12:55 +08:00
}
2020-11-18 23:15:59 +08:00
class ImagePaint extends StatelessWidget {
@override
Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context);
2020-11-23 23:18:42 +08:00
final c = Provider.of<CanvasModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
2020-11-23 23:18:42 +08:00
var s = c.scale;
2020-11-18 23:15:59 +08:00
return CustomPaint(
painter: ImagePainter(
2020-11-25 11:20:40 +08:00
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s),
2020-11-19 18:22:06 +08:00
);
}
}
class CursorPaint extends StatelessWidget {
@override
Widget build(BuildContext context) {
final m = Provider.of<CursorModel>(context);
2020-11-23 23:18:42 +08:00
final c = Provider.of<CanvasModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
2020-11-23 23:18:42 +08:00
var s = c.scale;
double hotx = m.hotx;
double hoty = m.hoty;
if (m.image == null) {
if (preDefaultCursor.image != null) {
hotx = preDefaultCursor.image!.width / 2;
hoty = preDefaultCursor.image!.height / 2;
}
}
2020-11-19 18:22:06 +08:00
return CustomPaint(
painter: ImagePainter(
image: m.image ?? preDefaultCursor.image,
x: m.x * s - hotx + c.x,
y: m.y * s - hoty + c.y - adjust,
2020-11-23 23:18:42 +08:00
scale: 1),
2020-11-18 23:15:59 +08:00
);
}
}
void showOptions(
BuildContext context, String id, OverlayDialogManager dialogManager) async {
2020-11-25 23:52:58 +08:00
var displays = <Widget>[];
final pi = gFFI.ffiModel.pi;
final image = gFFI.ffiModel.getConnectionImage();
2022-09-16 20:31:01 +08:00
if (image != null) {
displays.add(Padding(padding: const EdgeInsets.only(top: 8), child: image));
2022-09-16 20:31:01 +08:00
}
if (pi.displays.length > 1 && pi.currentDisplay != kAllDisplayValue) {
2020-11-25 23:52:58 +08:00
final cur = pi.currentDisplay;
final children = <Widget>[];
2022-09-16 20:31:01 +08:00
for (var i = 0; i < pi.displays.length; ++i) {
2020-11-25 23:52:58 +08:00
children.add(InkWell(
onTap: () {
if (i == cur) return;
openMonitorInTheSameTab(i, gFFI, pi);
2022-08-12 18:42:02 +08:00
gFFI.dialogManager.dismissAll();
2020-11-25 23:52:58 +08:00
},
child: Ink(
width: 40,
height: 40,
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).hintColor),
borderRadius: BorderRadius.circular(2),
color: i == cur
? Theme.of(context).toggleableActiveColor.withOpacity(0.6)
: null),
2020-11-25 23:52:58 +08:00
child: Center(
child: Text((i + 1).toString(),
style: TextStyle(
color: i == cur ? Colors.white : Colors.black87,
fontWeight: FontWeight.bold))))));
2022-09-16 20:31:01 +08:00
}
2020-11-25 23:52:58 +08:00
displays.add(Padding(
padding: const EdgeInsets.only(top: 8),
child: Wrap(
alignment: WrapAlignment.center,
spacing: 8,
children: children,
)));
}
if (displays.isNotEmpty) {
2022-09-16 20:31:01 +08:00
displays.add(const Divider(color: MyTheme.border));
2020-11-25 23:52:58 +08:00
}
2022-03-13 00:32:44 +08:00
List<TRadioMenu<String>> viewStyleRadios =
await toolbarViewStyle(context, id, gFFI);
List<TRadioMenu<String>> imageQualityRadios =
await toolbarImageQuality(context, id, gFFI);
List<TRadioMenu<String>> codecRadios = await toolbarCodec(context, id, gFFI);
List<TToggleMenu> displayToggles =
await toolbarDisplayToggle(context, id, gFFI);
2022-09-16 20:31:01 +08:00
List<TToggleMenu> privacyModeList = [];
// privacy mode
final privacyModeState = PrivacyModeState.find(id);
if (gFFI.ffiModel.keyboard && gFFI.ffiModel.pi.features.privacyMode) {
privacyModeList = toolbarPrivacyMode(privacyModeState, context, id, gFFI);
if (privacyModeList.length == 1) {
displayToggles.add(privacyModeList[0]);
}
}
2023-05-08 12:34:19 +08:00
dialogManager.show((setState, close, context) {
var viewStyle =
(viewStyleRadios.isNotEmpty ? viewStyleRadios[0].groupValue : '').obs;
var imageQuality =
(imageQualityRadios.isNotEmpty ? imageQualityRadios[0].groupValue : '')
.obs;
var codec = (codecRadios.isNotEmpty ? codecRadios[0].groupValue : '').obs;
2022-09-16 20:31:01 +08:00
final radios = [
for (var e in viewStyleRadios)
Obx(() => getRadio<String>(e.child, e.value, viewStyle.value, (v) {
e.onChanged?.call(v);
if (v != null) viewStyle.value = v;
})),
2022-09-16 20:31:01 +08:00
const Divider(color: MyTheme.border),
for (var e in imageQualityRadios)
Obx(() => getRadio<String>(e.child, e.value, imageQuality.value, (v) {
e.onChanged?.call(v);
if (v != null) imageQuality.value = v;
})),
const Divider(color: MyTheme.border),
for (var e in codecRadios)
Obx(() => getRadio<String>(e.child, e.value, codec.value, (v) {
e.onChanged?.call(v);
if (v != null) codec.value = v;
})),
if (codecRadios.isNotEmpty) const Divider(color: MyTheme.border),
2022-09-16 20:31:01 +08:00
];
final rxToggleValues = displayToggles.map((e) => e.value.obs).toList();
final toggles = displayToggles
.asMap()
.entries
.map((e) => Obx(() => CheckboxListTile(
contentPadding: EdgeInsets.zero,
visualDensity: VisualDensity.compact,
value: rxToggleValues[e.key].value,
onChanged: (v) {
e.value.onChanged?.call(v);
if (v != null) rxToggleValues[e.key].value = v;
},
title: e.value.child)))
.toList();
2022-09-16 20:31:01 +08:00
Widget privacyModeWidget = Offstage();
if (privacyModeList.length > 1) {
privacyModeWidget = ListTile(
contentPadding: EdgeInsets.zero,
visualDensity: VisualDensity.compact,
title: Text(translate('Privacy mode')),
onTap: () => setPrivacyModeDialog(
dialogManager, privacyModeList, privacyModeState),
);
}
2022-03-13 00:32:44 +08:00
return CustomAlertDialog(
2022-03-13 23:07:52 +08:00
content: Column(
mainAxisSize: MainAxisSize.min,
children: displays + radios + toggles + [privacyModeWidget]),
2022-03-13 00:32:44 +08:00
);
2022-04-21 10:02:47 +08:00
}, clickMaskDismiss: true, backDismiss: true);
2022-08-04 17:24:02 +08:00
}
2021-08-11 00:22:47 +08:00
void sendPrompt(bool isMac, String key) {
2022-09-27 20:35:02 +08:00
final old = isMac ? gFFI.inputModel.command : gFFI.inputModel.ctrl;
2021-08-11 00:22:47 +08:00
if (isMac) {
2022-09-27 20:35:02 +08:00
gFFI.inputModel.command = true;
2021-08-11 00:22:47 +08:00
} else {
2022-09-27 20:35:02 +08:00
gFFI.inputModel.ctrl = true;
2021-08-11 00:22:47 +08:00
}
2022-09-27 20:35:02 +08:00
gFFI.inputModel.inputKey(key);
2021-08-11 00:22:47 +08:00
if (isMac) {
2022-09-27 20:35:02 +08:00
gFFI.inputModel.command = old;
2021-08-11 00:22:47 +08:00
} else {
2022-09-27 20:35:02 +08:00
gFFI.inputModel.ctrl = old;
2021-08-11 00:22:47 +08:00
}
}
class FABLocation extends FloatingActionButtonLocation {
FloatingActionButtonLocation location;
double offsetX;
double offsetY;
FABLocation(this.location, this.offsetX, this.offsetY);
@override
Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
final offset = location.getOffset(scaffoldGeometry);
return Offset(offset.dx + offsetX, offset.dy + offsetY);
}
}