Merge branch 'flutter_desktop'

This commit is contained in:
Asura
2022-08-26 22:00:49 -07:00
10 changed files with 298 additions and 211 deletions

View File

@@ -234,6 +234,89 @@ class _RemotePageState extends State<RemotePage>
buildBody(context, ffiModel))));
}
KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
String? keyboardMode = Platform.environment['KEYBOARD_MODE'];
keyboardMode ??= 'legacy';
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;
debugPrint(newData.unicodeScalarValues.toString());
} else {
scanCode = -1;
keyCode = -1;
}
if (e is RawKeyDownEvent){
down = true;
}else{
down = false;
}
_ffi.inputRawKey(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) {
_ffi.command = false;
}
sendRawKey(e);
}
}
Widget getRawPointerAndKeyBody(Widget child) {
return Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion(
@@ -249,42 +332,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))));
}

View File

@@ -980,6 +980,12 @@ class FFI {
msg: json.encode(modify({'type': type, 'buttons': button.value})));
}
// Raw Key
void inputRawKey(int keyCode, int scanCode, bool down){
debugPrint(scanCode.toString());
bind.sessionInputRawKey(id: id, keycode: keyCode, scancode: scanCode, down: down);
}
/// Send key stroke event.
/// [down] indicates the key's state(down or up).
/// [press] indicates a click event(down and up).

View File

@@ -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