mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
Merge pull request #5323 from dignow/refact/android_scroll_event
Refact/android scroll event
This commit is contained in:
@@ -1130,6 +1130,85 @@ pub fn stop_global_event_stream(app_type: String) {
|
||||
let _ = GLOBAL_EVENT_STREAM.write().unwrap().remove(&app_type);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn session_send_touch_scale(
|
||||
session_id: SessionID,
|
||||
v: &serde_json::Value,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
command: bool,
|
||||
) {
|
||||
match v.get("v").and_then(|s| s.as_i64()) {
|
||||
Some(scale) => {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
||||
session.send_touch_scale(scale as _, alt, ctrl, shift, command);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn session_send_touch_pan(
|
||||
session_id: SessionID,
|
||||
v: &serde_json::Value,
|
||||
pan_event: &str,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
command: bool,
|
||||
) {
|
||||
match v.get("v") {
|
||||
Some(v) => match (
|
||||
v.get("x").and_then(|x| x.as_i64()),
|
||||
v.get("y").and_then(|y| y.as_i64()),
|
||||
) {
|
||||
(Some(x), Some(y)) => {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
||||
session
|
||||
.send_touch_pan_event(pan_event, x as _, y as _, alt, ctrl, shift, command);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn session_send_touch_event(
|
||||
session_id: SessionID,
|
||||
v: &serde_json::Value,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
command: bool,
|
||||
) {
|
||||
match v.get("t").and_then(|t| t.as_str()) {
|
||||
Some("scale") => session_send_touch_scale(session_id, v, alt, ctrl, shift, command),
|
||||
Some(pan_event) => {
|
||||
session_send_touch_pan(session_id, v, pan_event, alt, ctrl, shift, command)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_send_pointer(session_id: SessionID, msg: String) {
|
||||
if let Ok(m) = serde_json::from_str::<HashMap<String, serde_json::Value>>(&msg) {
|
||||
let alt = m.get("alt").is_some();
|
||||
let ctrl = m.get("ctrl").is_some();
|
||||
let shift = m.get("shift").is_some();
|
||||
let command = m.get("command").is_some();
|
||||
match (m.get("k"), m.get("v")) {
|
||||
(Some(k), Some(v)) => match k.as_str() {
|
||||
Some("touch") => session_send_touch_event(session_id, v, alt, ctrl, shift, command),
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
unsafe extern "C" fn get_rgba() {}
|
||||
|
||||
|
||||
@@ -1179,21 +1179,7 @@ pub fn main_load_ab() -> String {
|
||||
}
|
||||
|
||||
pub fn session_send_pointer(session_id: SessionID, msg: String) {
|
||||
if let Ok(m) = serde_json::from_str::<HashMap<String, serde_json::Value>>(&msg) {
|
||||
let alt = m.get("alt").is_some();
|
||||
let ctrl = m.get("ctrl").is_some();
|
||||
let shift = m.get("shift").is_some();
|
||||
let command = m.get("command").is_some();
|
||||
if let Some(touch_event) = m.get("touch") {
|
||||
if let Some(scale) = touch_event.get("scale") {
|
||||
if let Some(session) = SESSIONS.read().unwrap().get(&session_id) {
|
||||
if let Some(scale) = scale.as_i64() {
|
||||
session.send_touch_scale(scale as _, alt, ctrl, shift, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super::flutter::session_send_pointer(session_id, msg);
|
||||
}
|
||||
|
||||
pub fn session_send_mouse(session_id: SessionID, msg: String) {
|
||||
|
||||
@@ -39,7 +39,7 @@ use hbb_common::{
|
||||
tokio_util::codec::{BytesCodec, Framed},
|
||||
};
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
use scrap::android::call_main_service_mouse_input;
|
||||
use scrap::android::call_main_service_pointer_input;
|
||||
use serde_json::{json, value::Value};
|
||||
use sha2::{Digest, Sha256};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
@@ -1547,8 +1547,8 @@ impl Connection {
|
||||
match msg.union {
|
||||
Some(message::Union::MouseEvent(me)) => {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
if let Err(e) = call_main_service_mouse_input(me.mask, me.x, me.y) {
|
||||
log::debug!("call_main_service_mouse_input fail:{}", e);
|
||||
if let Err(e) = call_main_service_pointer_input("mouse", me.mask, me.x, me.y) {
|
||||
log::debug!("call_main_service_pointer_input fail:{}", e);
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.peer_keyboard_enabled() {
|
||||
@@ -1560,8 +1560,35 @@ impl Connection {
|
||||
self.input_mouse(me, self.inner.id());
|
||||
}
|
||||
}
|
||||
Some(message::Union::PointerDeviceEvent(pde)) =>
|
||||
{
|
||||
Some(message::Union::PointerDeviceEvent(pde)) => {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
if let Err(e) = match pde.union {
|
||||
Some(pointer_device_event::Union::TouchEvent(touch)) => match touch.union {
|
||||
Some(touch_event::Union::PanStart(pan_start)) => {
|
||||
call_main_service_pointer_input(
|
||||
"touch",
|
||||
4,
|
||||
pan_start.x,
|
||||
pan_start.y,
|
||||
)
|
||||
}
|
||||
Some(touch_event::Union::PanUpdate(pan_update)) => {
|
||||
call_main_service_pointer_input(
|
||||
"touch",
|
||||
5,
|
||||
pan_update.x,
|
||||
pan_update.y,
|
||||
)
|
||||
}
|
||||
Some(touch_event::Union::PanEnd(pan_end)) => {
|
||||
call_main_service_pointer_input("touch", 6, pan_end.x, pan_end.y)
|
||||
}
|
||||
_ => Ok(()),
|
||||
},
|
||||
_ => Ok(()),
|
||||
} {
|
||||
log::debug!("call_main_service_pointer_input fail:{}", e);
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
if self.peer_keyboard_enabled() {
|
||||
MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst);
|
||||
|
||||
@@ -724,6 +724,49 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
|
||||
}
|
||||
|
||||
pub fn send_touch_pan_event(
|
||||
&self,
|
||||
event: &str,
|
||||
x: i32,
|
||||
y: i32,
|
||||
alt: bool,
|
||||
ctrl: bool,
|
||||
shift: bool,
|
||||
command: bool,
|
||||
) {
|
||||
let mut touch_evt = TouchEvent::new();
|
||||
match event {
|
||||
"pan_start" => {
|
||||
touch_evt.set_pan_start(TouchPanStart {
|
||||
x,
|
||||
y,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
"pan_update" => {
|
||||
touch_evt.set_pan_update(TouchPanUpdate {
|
||||
x,
|
||||
y,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
"pan_end" => {
|
||||
touch_evt.set_pan_end(TouchPanEnd {
|
||||
x,
|
||||
y,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
_ => {
|
||||
log::warn!("unknown touch pan event: {}", event);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let mut evt = PointerDeviceEvent::new();
|
||||
evt.set_touch_event(touch_evt);
|
||||
send_pointer_device_event(evt, alt, ctrl, shift, command, self);
|
||||
}
|
||||
|
||||
pub fn send_mouse(
|
||||
&self,
|
||||
mask: i32,
|
||||
|
||||
Reference in New Issue
Block a user