diff --git a/flutter/lib/desktop/pages/remote_page.dart b/flutter/lib/desktop/pages/remote_page.dart index 8c56f69d2..c2bf4ea5b 100644 --- a/flutter/lib/desktop/pages/remote_page.dart +++ b/flutter/lib/desktop/pages/remote_page.dart @@ -41,6 +41,7 @@ class _RemotePageState extends State Timer? _timer; bool _showBar = !isWebDesktop; String _value = ''; + String keyboardMode = "legacy"; final _cursorOverImage = false.obs; final FocusNode _mobileFocusNode = FocusNode(); @@ -254,8 +255,11 @@ class _RemotePageState extends State } KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) { - String? keyboardMode = Platform.environment['KEYBOARD_MODE']; - keyboardMode ??= 'legacy'; + bind.sessionGetKeyboardName(id: widget.id).then((result) { + setState(() { + keyboardMode = result.toString(); + }); + }); if (keyboardMode == 'map') { mapKeyboardMode(e); @@ -285,7 +289,6 @@ class _RemotePageState extends State RawKeyEventDataLinux newData = e.data as RawKeyEventDataLinux; scanCode = newData.scanCode; keyCode = newData.keyCode; - debugPrint(newData.unicodeScalarValues.toString()); } else { scanCode = -1; keyCode = -1; @@ -537,10 +540,8 @@ class _RemotePageState extends State onPointerUp: _onPointUpImage, onPointerMove: _onPointMoveImage, onPointerSignal: _onPointerSignalImage, - child: MouseRegion( - onEnter: enterView, - onExit: leaveView, - child: child)); + child: + MouseRegion(onEnter: enterView, onExit: leaveView, child: child)); } Widget getBodyForDesktop(BuildContext context, bool keyboard) { diff --git a/flutter/lib/desktop/widgets/remote_menubar.dart b/flutter/lib/desktop/widgets/remote_menubar.dart index 47536011d..4d27c107f 100644 --- a/flutter/lib/desktop/widgets/remote_menubar.dart +++ b/flutter/lib/desktop/widgets/remote_menubar.dart @@ -93,6 +93,7 @@ class _RemoteMenubarState extends State { 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 { ); } + 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'), @@ -555,6 +579,28 @@ class _RemoteMenubarState extends State { return displayMenu; } + List> _getKeyboardMenu() { + final keyboardMenu = [ + MenuEntryRadios( + 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 _createSwitchMenuEntry(String text, String option) { return MenuEntrySwitch( text: translate(text), diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index bfa6f5297..b1cc6192b 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -1003,6 +1003,10 @@ class FFI { downOrUp: down); } + Future getKeyboardMode(){ + return bind.sessionGetKeyboardName(id: id); + } + void enterOrLeave(bool enter) { bind.sessionEnterOrLeave(id: id, enter: enter); } diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index e5616bee6..d2d49fff0 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -298,6 +298,19 @@ pub fn session_get_peer_option(id: String, name: String) -> String { "".to_string() } +pub fn session_get_keyboard_name(id: String) -> String { + if let Some(session) = SESSIONS.read().unwrap().get(&id) { + return session.get_keyboard_mode(); + } + "legacy".to_string() +} + +pub fn session_set_keyboard_mode(id: String, keyboard_mode: String) { + if let Some(session) = SESSIONS.read().unwrap().get(&id) { + session.save_keyboard_mode(keyboard_mode); + } +} + pub fn session_input_os_password(id: String, value: String) { if let Some(session) = SESSIONS.read().unwrap().get(&id) { session.input_os_password(value, true);