Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Dec 6, 2024
2 parents 1998f79 + 12e15b5 commit 46dceea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 38 deletions.
2 changes: 2 additions & 0 deletions libs/hbb_common/protos/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ enum ControlKey {
}

message KeyEvent {
// `down` indicates the key's state(down or up).
bool down = 1;
// `press` indicates a click event(down and up).
bool press = 2;
oneof union {
ControlKey control_key = 3;
Expand Down
1 change: 1 addition & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2748,6 +2748,7 @@ fn _input_os_password(p: String, activate: bool, interface: impl Interface) {
return;
}
let mut key_event = KeyEvent::new();
key_event.mode = KeyboardMode::Legacy.into();
key_event.press = true;
let mut msg_out = Message::new();
key_event.set_seq(p);
Expand Down
40 changes: 15 additions & 25 deletions src/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,17 @@ pub fn is_modifier(key: &rdev::Key) -> bool {
)
}

#[inline]
pub fn is_modifier_code(evt: &KeyEvent) -> bool {
match evt.union {
Some(key_event::Union::Chr(code)) => {
let key = rdev::linux_key_from_code(code);
is_modifier(&key)
}
_ => false,
}
}

#[inline]
pub fn is_numpad_rdev_key(key: &rdev::Key) -> bool {
matches!(
Expand Down Expand Up @@ -869,24 +880,11 @@ pub fn legacy_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Vec<KeyEv
events
}

#[inline]
pub fn map_keyboard_mode(_peer: &str, event: &Event, key_event: KeyEvent) -> Vec<KeyEvent> {
match _map_keyboard_mode(_peer, event, key_event) {
Some(key_event) => {
if _peer == OS_LOWER_LINUX {
if let EventType::KeyPress(k) = &event.event_type {
#[cfg(target_os = "ios")]
let try_workaround = true;
#[cfg(not(target_os = "ios"))]
let try_workaround = !is_modifier(k);
if try_workaround {
return try_workaround_linux_long_press(key_event);
}
}
}
vec![key_event]
}
None => Vec::new(),
}
_map_keyboard_mode(_peer, event, key_event)
.map(|e| vec![e])
.unwrap_or_default()
}

fn _map_keyboard_mode(_peer: &str, event: &Event, mut key_event: KeyEvent) -> Option<KeyEvent> {
Expand Down Expand Up @@ -958,14 +956,6 @@ fn _map_keyboard_mode(_peer: &str, event: &Event, mut key_event: KeyEvent) -> Op
Some(key_event)
}

// https://github.com/rustdesk/rustdesk/issues/6793
#[inline]
fn try_workaround_linux_long_press(key_event: KeyEvent) -> Vec<KeyEvent> {
let mut key_event_up = key_event.clone();
key_event_up.down = false;
vec![key_event, key_event_up]
}

#[cfg(not(any(target_os = "ios")))]
fn try_fill_unicode(_peer: &str, event: &Event, key_event: &KeyEvent, events: &mut Vec<KeyEvent>) {
match &event.unicode {
Expand Down
30 changes: 17 additions & 13 deletions src/server/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,13 @@ impl Connection {
handle_mouse(&msg, id);
}
MessageInput::Key((mut msg, press)) => {
// todo: press and down have similar meanings.
if press && msg.mode.enum_value() == Ok(KeyboardMode::Legacy) {
// Set the press state to false, use `down` only in `handle_key()`.
msg.press = false;
if press {
msg.down = true;
}
handle_key(&msg);
if press && msg.mode.enum_value() == Ok(KeyboardMode::Legacy) {
if press {
msg.down = false;
handle_key(&msg);
}
Expand Down Expand Up @@ -1965,8 +1966,6 @@ impl Connection {
Some(message::Union::KeyEvent(..)) => {}
#[cfg(any(target_os = "android"))]
Some(message::Union::KeyEvent(mut me)) => {
let is_press = (me.press || me.down) && !crate::is_modifier(&me);

let key = match me.mode.enum_value() {
Ok(KeyboardMode::Map) => {
Some(crate::keyboard::keycode_to_rdev_key(me.chr()))
Expand All @@ -1982,6 +1981,9 @@ impl Connection {
}
.filter(crate::keyboard::is_modifier);

let is_press =
(me.press || me.down) && !(crate::is_modifier(&me) || key.is_some());

if let Some(key) = key {
if is_press {
self.pressed_modifiers.insert(key);
Expand Down Expand Up @@ -2022,14 +2024,6 @@ impl Connection {
}
// https://github.com/rustdesk/rustdesk/issues/8633
MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst);
// handle all down as press
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which
// make sure all key are released
let is_press = if cfg!(target_os = "linux") {
(me.press || me.down) && !crate::is_modifier(&me)
} else {
me.press
};

let key = match me.mode.enum_value() {
Ok(KeyboardMode::Map) => {
Expand All @@ -2046,6 +2040,16 @@ impl Connection {
}
.filter(crate::keyboard::is_modifier);

// handle all down as press
// fix unexpected repeating key on remote linux, seems also fix abnormal alt/shift, which
// make sure all key are released
// https://github.com/rustdesk/rustdesk/issues/6793
let is_press = if cfg!(target_os = "linux") {
(me.press || me.down) && !(crate::is_modifier(&me) || key.is_some())
} else {
me.press
};

if let Some(key) = key {
if is_press {
self.pressed_modifiers.insert(key);
Expand Down

0 comments on commit 46dceea

Please sign in to comment.