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

View File

@ -234,22 +234,54 @@ class _RemotePageState extends State<RemotePage>
buildBody(context, ffiModel)))); buildBody(context, ffiModel))));
} }
Widget getRawPointerAndKeyBody(Widget child) { KeyEventResult handleRawKeyEvent(FocusNode data, RawKeyEvent e) {
return Consumer<FfiModel>( String? keyboardMode = Platform.environment['KEYBOARD_MODE'];
builder: (context, FfiModel, _child) => MouseRegion( keyboardMode ??= 'legacy';
cursor: FfiModel.permissions['keyboard'] != false
? SystemMouseCursors.none if (keyboardMode == 'map') {
: MouseCursor.defer, mapKeyboardMode(e);
child: FocusScope( } else if (keyboardMode == 'translate') {
autofocus: true, legacyKeyboardMode(e);
child: Focus( } else {
autofocus: true, legacyKeyboardMode(e);
canRequestFocus: true, }
focusNode: _physicalFocusNode,
onFocusChange: (bool v) { return KeyEventResult.handled;
_imageFocused = v; }
},
onKey: (data, e) { 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; final key = e.logicalKey;
if (e is RawKeyDownEvent) { if (e is RawKeyDownEvent) {
if (e.repeat) { if (e.repeat) {
@ -283,8 +315,24 @@ class _RemotePageState extends State<RemotePage>
} }
sendRawKey(e); sendRawKey(e);
} }
return KeyEventResult.handled; }
Widget getRawPointerAndKeyBody(Widget child) {
return Consumer<FfiModel>(
builder: (context, FfiModel, _child) => MouseRegion(
cursor: FfiModel.permissions['keyboard'] != false
? SystemMouseCursors.none
: MouseCursor.defer,
child: FocusScope(
autofocus: true,
child: Focus(
autofocus: true,
canRequestFocus: true,
focusNode: _physicalFocusNode,
onFocusChange: (bool v) {
_imageFocused = v;
}, },
onKey: handleRawKeyEvent,
child: child)))); child: child))));
} }

View File

@ -980,6 +980,12 @@ class FFI {
msg: json.encode(modify({'type': type, 'buttons': button.value}))); 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. /// Send key stroke event.
/// [down] indicates the key's state(down or up). /// [down] indicates the key's state(down or up).
/// [press] indicates a click event(down and up). /// [press] indicates a click event(down and up).

View File

@ -97,7 +97,7 @@ class PlatformFFI {
final dylib = Platform.isAndroid final dylib = Platform.isAndroid
? DynamicLibrary.open('librustdesk.so') ? DynamicLibrary.open('librustdesk.so')
: Platform.isLinux : Platform.isLinux
? DynamicLibrary.open("/usr/lib/rustdesk/librustdesk.so") ? DynamicLibrary.open("librustdesk.so")
: Platform.isWindows : Platform.isWindows
? DynamicLibrary.open("librustdesk.dll") ? DynamicLibrary.open("librustdesk.dll")
: Platform.isMacOS : Platform.isMacOS

View File

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

View File

@ -1,7 +1,8 @@
#include <dlfcn.h> #include <dlfcn.h>
#include "my_application.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)(); typedef bool (*RustDeskCoreMain)();
bool flutter_rustdesk_core_main() { 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. /// Keycode for key events.
#[derive(Clone)] #[derive(Clone, Debug)]
pub enum Key { pub enum Key {
ControlKey(ControlKey), ControlKey(ControlKey),
Chr(u32), 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. /// Input a string of text.
/// String is parsed into individual key presses. /// String is parsed into individual key presses.
/// ///
@ -471,7 +481,7 @@ impl Session {
} }
let mut msg_out = Message::new(); let mut msg_out = Message::new();
msg_out.set_key_event(key_event); msg_out.set_key_event(key_event);
log::debug!("{:?}", msg_out); // log::debug!("{:?}", msg_out);
self.send_msg(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( pub fn session_input_key(
id: String, id: String,
name: String, name: String,