mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Merge pull request #964 from asur4s/master
Feat: Support new keyboard mode
This commit is contained in:
@@ -41,6 +41,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
Timer? _timer;
|
||||
String _value = '';
|
||||
String keyboardMode = "legacy";
|
||||
final _cursorOverImage = false.obs;
|
||||
late RxBool _showRemoteCursor;
|
||||
late RxBool _remoteCursorMoved;
|
||||
@@ -246,6 +247,92 @@ class _RemotePageState extends State<RemotePage>
|
||||
], child: buildBody(context)));
|
||||
}
|
||||
|
||||
KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
|
||||
bind.sessionGetKeyboardName(id: widget.id).then((result) {
|
||||
setState(() {
|
||||
keyboardMode = result.toString();
|
||||
});
|
||||
});
|
||||
|
||||
if (keyboardMode == 'map') {
|
||||
mapKeyboardMode(e);
|
||||
} else if (keyboardMode == 'translate') {
|
||||
legacyKeyboardMode(e);
|
||||
} else {
|
||||
legacyKeyboardMode(e);
|
||||
}
|
||||
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
void mapKeyboardMode(RawKeyEvent e) {
|
||||
int scanCode;
|
||||
int keyCode;
|
||||
bool down;
|
||||
|
||||
if (e.data is RawKeyEventDataMacOs) {
|
||||
RawKeyEventDataMacOs newData = e.data as RawKeyEventDataMacOs;
|
||||
scanCode = newData.keyCode;
|
||||
keyCode = newData.keyCode;
|
||||
} else if (e.data is RawKeyEventDataWindows) {
|
||||
RawKeyEventDataWindows newData = e.data as RawKeyEventDataWindows;
|
||||
scanCode = newData.scanCode;
|
||||
keyCode = newData.keyCode;
|
||||
} else if (e.data is RawKeyEventDataLinux) {
|
||||
RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux;
|
||||
scanCode = newData.scanCode;
|
||||
keyCode = newData.keyCode;
|
||||
} else {
|
||||
scanCode = -1;
|
||||
keyCode = -1;
|
||||
}
|
||||
|
||||
if (e is RawKeyDownEvent) {
|
||||
down = true;
|
||||
} else {
|
||||
down = false;
|
||||
}
|
||||
|
||||
_ffi.inputRawKey(e.character ?? "", keyCode, scanCode, down);
|
||||
}
|
||||
|
||||
void legacyKeyboardMode(RawKeyEvent e) {
|
||||
final key = e.logicalKey;
|
||||
if (e is RawKeyDownEvent) {
|
||||
if (e.repeat) {
|
||||
sendRawKey(e, press: true);
|
||||
} else {
|
||||
if (e.isAltPressed && !_ffi.alt) {
|
||||
_ffi.alt = true;
|
||||
} else if (e.isControlPressed && !_ffi.ctrl) {
|
||||
_ffi.ctrl = true;
|
||||
} else if (e.isShiftPressed && !_ffi.shift) {
|
||||
_ffi.shift = true;
|
||||
} else if (e.isMetaPressed && !_ffi.command) {
|
||||
_ffi.command = true;
|
||||
}
|
||||
sendRawKey(e, down: true);
|
||||
}
|
||||
}
|
||||
if (e is RawKeyUpEvent) {
|
||||
if (key == LogicalKeyboardKey.altLeft ||
|
||||
key == LogicalKeyboardKey.altRight) {
|
||||
_ffi.alt = false;
|
||||
} else if (key == LogicalKeyboardKey.controlLeft ||
|
||||
key == LogicalKeyboardKey.controlRight) {
|
||||
_ffi.ctrl = false;
|
||||
} else if (key == LogicalKeyboardKey.shiftRight ||
|
||||
key == LogicalKeyboardKey.shiftLeft) {
|
||||
_ffi.shift = false;
|
||||
} else if (key == LogicalKeyboardKey.metaLeft ||
|
||||
key == LogicalKeyboardKey.metaRight ||
|
||||
key == LogicalKeyboardKey.superKey) {
|
||||
_ffi.command = false;
|
||||
}
|
||||
sendRawKey(e);
|
||||
}
|
||||
}
|
||||
|
||||
Widget getRawPointerAndKeyBody(Widget child) {
|
||||
return FocusScope(
|
||||
autofocus: true,
|
||||
@@ -256,42 +343,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
onFocusChange: (bool v) {
|
||||
_imageFocused = v;
|
||||
},
|
||||
onKey: (data, e) {
|
||||
final key = e.logicalKey;
|
||||
if (e is RawKeyDownEvent) {
|
||||
if (e.repeat) {
|
||||
sendRawKey(e, press: true);
|
||||
} else {
|
||||
if (e.isAltPressed && !_ffi.alt) {
|
||||
_ffi.alt = true;
|
||||
} else if (e.isControlPressed && !_ffi.ctrl) {
|
||||
_ffi.ctrl = true;
|
||||
} else if (e.isShiftPressed && !_ffi.shift) {
|
||||
_ffi.shift = true;
|
||||
} else if (e.isMetaPressed && !_ffi.command) {
|
||||
_ffi.command = true;
|
||||
}
|
||||
sendRawKey(e, down: true);
|
||||
}
|
||||
}
|
||||
if (e is RawKeyUpEvent) {
|
||||
if (key == LogicalKeyboardKey.altLeft ||
|
||||
key == LogicalKeyboardKey.altRight) {
|
||||
_ffi.alt = false;
|
||||
} else if (key == LogicalKeyboardKey.controlLeft ||
|
||||
key == LogicalKeyboardKey.controlRight) {
|
||||
_ffi.ctrl = false;
|
||||
} else if (key == LogicalKeyboardKey.shiftRight ||
|
||||
key == LogicalKeyboardKey.shiftLeft) {
|
||||
_ffi.shift = false;
|
||||
} else if (key == LogicalKeyboardKey.metaLeft ||
|
||||
key == LogicalKeyboardKey.metaRight) {
|
||||
_ffi.command = false;
|
||||
}
|
||||
sendRawKey(e);
|
||||
}
|
||||
return KeyEventResult.handled;
|
||||
},
|
||||
onKey: handleRawKeyEvent,
|
||||
child: child));
|
||||
}
|
||||
|
||||
@@ -304,7 +356,6 @@ class _RemotePageState extends State<RemotePage>
|
||||
/// mouseMode only:
|
||||
/// DoubleFiner -> right click
|
||||
/// HoldDrag -> left drag
|
||||
|
||||
void _onPointHoverImage(PointerHoverEvent e) {
|
||||
if (e.kind != ui.PointerDeviceKind.mouse) return;
|
||||
if (!_isPhysicalMouse) {
|
||||
@@ -367,6 +418,19 @@ class _RemotePageState extends State<RemotePage>
|
||||
}
|
||||
}
|
||||
|
||||
void enterView(PointerEnterEvent evt) {
|
||||
if (!_imageFocused) {
|
||||
_physicalFocusNode.requestFocus();
|
||||
}
|
||||
_cursorOverImage.value = true;
|
||||
_ffi.enterOrLeave(true);
|
||||
}
|
||||
|
||||
void leaveView(PointerExitEvent evt) {
|
||||
_cursorOverImage.value = false;
|
||||
_ffi.enterOrLeave(false);
|
||||
}
|
||||
|
||||
Widget _buildImageListener(Widget child) {
|
||||
return Listener(
|
||||
onPointerHover: _onPointHoverImage,
|
||||
@@ -374,17 +438,8 @@ class _RemotePageState extends State<RemotePage>
|
||||
onPointerUp: _onPointUpImage,
|
||||
onPointerMove: _onPointMoveImage,
|
||||
onPointerSignal: _onPointerSignalImage,
|
||||
child: MouseRegion(
|
||||
onEnter: (evt) {
|
||||
if (!_imageFocused) {
|
||||
_physicalFocusNode.requestFocus();
|
||||
}
|
||||
_cursorOverImage.value = true;
|
||||
},
|
||||
onExit: (evt) {
|
||||
_cursorOverImage.value = false;
|
||||
},
|
||||
child: child));
|
||||
child:
|
||||
MouseRegion(onEnter: enterView, onExit: leaveView, child: child));
|
||||
}
|
||||
|
||||
Widget getBodyForDesktop(BuildContext context) {
|
||||
|
||||
@@ -93,6 +93,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
menubarItems.add(_buildMonitor(context));
|
||||
menubarItems.add(_buildControl(context));
|
||||
menubarItems.add(_buildDisplay(context));
|
||||
menubarItems.add(_buildKeyboard(context));
|
||||
if (!isWeb) {
|
||||
menubarItems.add(_buildChat(context));
|
||||
}
|
||||
@@ -264,6 +265,29 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildKeyboard(BuildContext context) {
|
||||
return mod_menu.PopupMenuButton(
|
||||
padding: EdgeInsets.zero,
|
||||
icon: const Icon(
|
||||
Icons.keyboard,
|
||||
color: _MenubarTheme.commonColor,
|
||||
),
|
||||
tooltip: translate('Keyboard Settings'),
|
||||
position: mod_menu.PopupMenuPosition.under,
|
||||
onSelected: (String item) {},
|
||||
itemBuilder: (BuildContext context) => _getKeyboardMenu()
|
||||
.map((entry) => entry.build(
|
||||
context,
|
||||
const MenuConfig(
|
||||
commonColor: _MenubarTheme.commonColor,
|
||||
height: _MenubarTheme.height,
|
||||
dividerHeight: _MenubarTheme.dividerHeight,
|
||||
)))
|
||||
.expand((i) => i)
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClose(BuildContext context) {
|
||||
return IconButton(
|
||||
tooltip: translate('Close'),
|
||||
@@ -577,6 +601,28 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
return displayMenu;
|
||||
}
|
||||
|
||||
List<MenuEntryBase<String>> _getKeyboardMenu() {
|
||||
final keyboardMenu = [
|
||||
MenuEntryRadios<String>(
|
||||
text: translate('Ratio'),
|
||||
optionsGetter: () => [
|
||||
MenuEntryRadioOption(
|
||||
text: translate('Legacy mode'), value: 'legacy'),
|
||||
MenuEntryRadioOption(text: translate('Map mode'), value: 'map'),
|
||||
],
|
||||
curOptionGetter: () async {
|
||||
return await bind.sessionGetKeyboardName(id: widget.id) ?? 'legacy';
|
||||
},
|
||||
optionSetter: (String oldValue, String newValue) async {
|
||||
await bind.sessionSetKeyboardMode(
|
||||
id: widget.id, keyboardMode: newValue);
|
||||
widget.ffi.canvasModel.updateViewStyle();
|
||||
})
|
||||
];
|
||||
|
||||
return keyboardMenu;
|
||||
}
|
||||
|
||||
MenuEntrySwitch<String> _createSwitchMenuEntry(String text, String option) {
|
||||
return MenuEntrySwitch<String>(
|
||||
text: translate(text),
|
||||
|
||||
@@ -972,6 +972,28 @@ class FFI {
|
||||
msg: json.encode(modify({'type': type, 'buttons': button.value})));
|
||||
}
|
||||
|
||||
// Raw Key
|
||||
void inputRawKey(String name, int keyCode, int scanCode, bool down) {
|
||||
bind.sessionHandleFlutterKeyEvent(
|
||||
id: id,
|
||||
name: name,
|
||||
keycode: keyCode,
|
||||
scancode: scanCode,
|
||||
downOrUp: down);
|
||||
}
|
||||
|
||||
Future<String> getKeyboardMode() {
|
||||
return bind.sessionGetKeyboardName(id: id);
|
||||
}
|
||||
|
||||
void enterOrLeave(bool enter) {
|
||||
// Fix status
|
||||
if (!enter) {
|
||||
resetModifiers();
|
||||
}
|
||||
bind.sessionEnterOrLeave(id: id, enter: enter);
|
||||
}
|
||||
|
||||
/// Send key stroke event.
|
||||
/// [down] indicates the key's state(down or up).
|
||||
/// [press] indicates a click event(down and up).
|
||||
|
||||
@@ -97,7 +97,7 @@ class PlatformFFI {
|
||||
final dylib = Platform.isAndroid
|
||||
? DynamicLibrary.open('librustdesk.so')
|
||||
: Platform.isLinux
|
||||
? DynamicLibrary.open("/usr/lib/rustdesk/librustdesk.so")
|
||||
? DynamicLibrary.open("librustdesk.so")
|
||||
: Platform.isWindows
|
||||
? DynamicLibrary.open("librustdesk.dll")
|
||||
: Platform.isMacOS
|
||||
|
||||
Reference in New Issue
Block a user