Merge branch 'flutter_desktop'

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

12
Cargo.lock generated
View File

@ -1379,18 +1379,30 @@ dependencies = [
[[package]]
name = "enum-map"
<<<<<<< HEAD
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ddfe61e8040145222887d0d32a939c70c8cae681490d72fb868305e9b40ced8"
=======
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5a56d54c8dd9b3ad34752ed197a4eb2a6601bc010808eb097a04a58ae4c43e1"
>>>>>>> flutter_desktop
dependencies = [
"enum-map-derive",
]
[[package]]
name = "enum-map-derive"
<<<<<<< HEAD
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d1c54e25a57236a790ecf051c2befbb57740c9b86c4273eac378ba84d620d6"
=======
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9045e2676cd5af83c3b167d917b0a5c90a4d8e266e2683d6631b235c457fc27"
>>>>>>> flutter_desktop
dependencies = [
"proc-macro2",
"quote",

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

View File

@ -74,6 +74,8 @@ corrosion_import_crate(MANIFEST_PATH ../../Cargo.toml
# [FEATURES <feature1> ... <featureN>]
)
set(BASE_RUSTDESK "librustdesk")
# Define the application target. To change its name, change BINARY_NAME above,
# not the value here, or `flutter run` will no longer work.
#
@ -91,8 +93,8 @@ apply_standard_settings(${BINARY_NAME})
# Add dependency libraries. Add any application-specific dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
target_link_libraries(${BINARY_NAME} PRIVATE librustdesk)
target_link_libraries(${BINARY_NAME} PRIVATE ${BASE_RUSTDESK})
# target_link_libraries(${BINARY_NAME} PRIVATE librustdesk)
# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)
@ -142,6 +144,8 @@ foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
COMPONENT Runtime)
endforeach(bundled_library)
install(FILES $<TARGET_FILE:${BASE_RUSTDESK}-shared> DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime RENAME librustdesk.so)
# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")

View File

@ -1,7 +1,8 @@
#include <dlfcn.h>
#include "my_application.h"
#define RUSTDESK_LIB_PATH "/usr/lib/rustdesk/librustdesk.so"
#define RUSTDESK_LIB_PATH "ibrustdesk.so"
// #define RUSTDESK_LIB_PATH "/usr/lib/rustdesk/librustdesk.so"
typedef bool (*RustDeskCoreMain)();
bool flutter_rustdesk_core_main() {

File diff suppressed because it is too large Load Diff

View File

@ -1681,7 +1681,7 @@ pub enum Data {
}
/// Keycode for key events.
#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum Key {
ControlKey(ControlKey),
Chr(u32),

View File

@ -373,6 +373,16 @@ impl Session {
}
}
pub fn input_raw_key(&self, keycode: i32, scancode: i32, down: bool){
use rdev::{EventType::*, Key as RdevKey, *};
if scancode < 0 || keycode < 0{
return;
}
let key = rdev::key_from_scancode(scancode.try_into().unwrap()) as RdevKey;
log::info!("{:?}", key);
}
/// Input a string of text.
/// String is parsed into individual key presses.
///
@ -471,7 +481,7 @@ impl Session {
}
let mut msg_out = Message::new();
msg_out.set_key_event(key_event);
log::debug!("{:?}", msg_out);
// log::debug!("{:?}", msg_out);
self.send_msg(msg_out);
}

View File

@ -208,6 +208,12 @@ pub fn session_switch_display(id: String, value: i32) {
}
}
pub fn session_input_raw_key(id: String, keycode: i32, scancode:i32, down: bool){
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.input_raw_key(keycode, scancode, down);
}
}
pub fn session_input_key(
id: String,
name: String,