mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
allow swap key
This commit is contained in:
@@ -428,8 +428,10 @@ pub fn session_add(
|
||||
let session_id = get_session_id(id.to_owned());
|
||||
LocalConfig::set_remote_id(&session_id);
|
||||
|
||||
let allow_swap_key = hbb_common::config::Config::get_option("allow-swap-key") == "Y";
|
||||
let session: Session<FlutterHandler> = Session {
|
||||
id: session_id.clone(),
|
||||
allow_swap_key,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
@@ -210,6 +210,53 @@ pub fn start_grab_loop() {
|
||||
if key == Key::CapsLock || key == Key::NumLock {
|
||||
return Some(event);
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
let mut event = event;
|
||||
#[cfg(target_os = "macos")] {
|
||||
let mut allow_swap_key = false;
|
||||
#[cfg(not(any(feature = "flutter", feature = "cli")))]
|
||||
if let Some(session) = CUR_SESSION.lock().unwrap().as_ref() {
|
||||
allow_swap_key = session.allow_swap_key;
|
||||
}
|
||||
#[cfg(feature = "flutter")]
|
||||
if let Some(session) = SESSIONS
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&*CUR_SESSION_ID.read().unwrap())
|
||||
{
|
||||
allow_swap_key = session.allow_swap_key;
|
||||
}
|
||||
if allow_swap_key {
|
||||
match event.event_type {
|
||||
EventType::KeyPress( key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyPress(key);
|
||||
event.scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
EventType::KeyRelease(key) => {
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
event.event_type = EventType::KeyRelease(key);
|
||||
event.scan_code = rdev::macos_keycode_from_key(key).unwrap_or_default();
|
||||
event.code = event.scan_code as _;
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
let mut _keyboard_mode = KeyboardMode::Map;
|
||||
let scan_code = event.scan_code;
|
||||
|
||||
@@ -539,6 +539,9 @@ impl Connection {
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
fn handle_input(receiver: std_mpsc::Receiver<MessageInput>, tx: Sender) {
|
||||
#[cfg(target_os = "macos")]
|
||||
let allow_swap_key = hbb_common::config::Config::get_option("allow-swap-key") == "Y";
|
||||
|
||||
let mut block_input_mode = false;
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
@@ -551,9 +554,66 @@ impl Connection {
|
||||
match receiver.recv_timeout(std::time::Duration::from_millis(500)) {
|
||||
Ok(v) => match v {
|
||||
MessageInput::Mouse((msg, id)) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
let msg = {
|
||||
let mut msg = msg;
|
||||
if allow_swap_key {
|
||||
msg.modifiers = msg.modifiers.iter().map(|ck| {
|
||||
let ck = ck.enum_value_or_default();
|
||||
let ck = match ck {
|
||||
ControlKey::Control => ControlKey::Meta,
|
||||
ControlKey::Meta => ControlKey::Control,
|
||||
ControlKey::RControl => ControlKey::Meta,
|
||||
ControlKey::RWin => ControlKey::Control,
|
||||
_ => ck,
|
||||
};
|
||||
hbb_common::protobuf::EnumOrUnknown::new(ck)
|
||||
}).collect();
|
||||
}
|
||||
msg
|
||||
};
|
||||
|
||||
handle_mouse(&msg, id);
|
||||
}
|
||||
MessageInput::Key((mut msg, press)) => {
|
||||
#[cfg(target_os = "macos")]
|
||||
if allow_swap_key {
|
||||
if let Some(key_event::Union::ControlKey(ck)) = msg.union {
|
||||
let ck = ck.enum_value_or_default();
|
||||
let ck = match ck {
|
||||
ControlKey::Control => ControlKey::Meta,
|
||||
ControlKey::Meta => ControlKey::Control,
|
||||
ControlKey::RControl => ControlKey::Meta,
|
||||
ControlKey::RWin => ControlKey::Control,
|
||||
_ => ck,
|
||||
};
|
||||
msg.set_control_key(ck);
|
||||
}
|
||||
msg.modifiers = msg.modifiers.iter().map(|ck| {
|
||||
let ck = ck.enum_value_or_default();
|
||||
let ck = match ck {
|
||||
ControlKey::Control => ControlKey::Meta,
|
||||
ControlKey::Meta => ControlKey::Control,
|
||||
ControlKey::RControl => ControlKey::Meta,
|
||||
ControlKey::RWin => ControlKey::Control,
|
||||
_ => ck,
|
||||
};
|
||||
hbb_common::protobuf::EnumOrUnknown::new(ck)
|
||||
}).collect();
|
||||
|
||||
let code = msg.chr();
|
||||
if code != 0 {
|
||||
let key = rdev::key_from_code(code);
|
||||
let key = match key {
|
||||
rdev::Key::ControlLeft => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaLeft => rdev::Key::ControlLeft,
|
||||
rdev::Key::ControlRight => rdev::Key::MetaLeft,
|
||||
rdev::Key::MetaRight => rdev::Key::ControlLeft,
|
||||
_ => key,
|
||||
};
|
||||
msg.set_chr(rdev::macos_keycode_from_key(key).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
// todo: press and down have similar meanings.
|
||||
if press && msg.mode.unwrap() == KeyboardMode::Legacy {
|
||||
msg.down = true;
|
||||
|
||||
@@ -214,6 +214,7 @@ class Enhancements: Reactor.Component {
|
||||
{has_hwcodec ? <li #enable-hwcodec><span>{svg_checkmark}</span>{translate("Hardware Codec")} (beta)</li> : ""}
|
||||
<li #enable-abr><span>{svg_checkmark}</span>{translate("Adaptive Bitrate")} (beta)</li>
|
||||
<li #screen-recording>{translate("Recording")}</li>
|
||||
{is_osx ? <li #allow-swap-key><span>{svg_checkmark}</span>{translate("Swap control-command key")} </li> : "" }
|
||||
</menu>
|
||||
</li>;
|
||||
}
|
||||
|
||||
@@ -443,10 +443,12 @@ impl sciter::EventHandler for SciterSession {
|
||||
|
||||
impl SciterSession {
|
||||
pub fn new(cmd: String, id: String, password: String, args: Vec<String>) -> Self {
|
||||
let allow_swap_key = hbb_common::config::Config::get_option("allow-swap-key") == "Y";
|
||||
let session: Session<SciterHandler> = Session {
|
||||
id: id.clone(),
|
||||
password: password.clone(),
|
||||
args,
|
||||
allow_swap_key,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ pub struct Session<T: InvokeUiSession> {
|
||||
pub sender: Arc<RwLock<Option<mpsc::UnboundedSender<Data>>>>,
|
||||
pub thread: Arc<Mutex<Option<std::thread::JoinHandle<()>>>>,
|
||||
pub ui_handler: T,
|
||||
pub allow_swap_key: bool,
|
||||
}
|
||||
|
||||
impl<T: InvokeUiSession> Session<T> {
|
||||
@@ -505,6 +506,15 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
shift: bool,
|
||||
command: bool,
|
||||
) {
|
||||
#[cfg(target_os = "macos")]
|
||||
let (ctrl, command) =
|
||||
if self.allow_swap_key {
|
||||
(command, ctrl)
|
||||
}
|
||||
else {
|
||||
(ctrl, command)
|
||||
};
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut command = command;
|
||||
#[cfg(windows)]
|
||||
|
||||
Reference in New Issue
Block a user