mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-05-07 14:48:11 +03:00
feat(shortcuts): user-configurable keyboard shortcuts for session actions
Adds a keyboard shortcut feature (Rust matcher + Dart UI + cross-language
parity tests) that lets users bind combinations like Ctrl+Alt+Shift+P to
session actions. Bindings are stored in LocalConfig under
`keyboard-shortcuts`; the matcher gates dispatch on `enabled` and
`pass_through` flags so flipping the master switch off is a hard stop.
Wire-up summary:
- src/keyboard/shortcuts.rs: matcher, default bindings, parity test against
flutter/test/fixtures/default_keyboard_shortcuts.json
- src/keyboard.rs: shortcut intercept in process_event{,_with_session},
feature-gated to `flutter`; runs before key swapping so users bind to
physical keys
- src/flutter_ffi.rs: main_reload_keyboard_shortcuts +
main_get_default_keyboard_shortcuts; reload_from_config seeded in main_init
- flutter/lib/common/widgets/keyboard_shortcuts/: shared config page body,
recording dialog, shortcut display formatter, action group registry
- flutter/lib/desktop/pages/desktop_keyboard_shortcuts_page.dart and
flutter/lib/mobile/pages/mobile_keyboard_shortcuts_page.dart: platform
shells around the shared body
- flutter/lib/models/shortcut_model.dart: per-session ShortcutModel +
registerSessionShortcutActions for actions with no toolbar TToggleMenu /
TRadioMenu (fullscreen, switch display/tab, close tab, voice call, etc.)
- flutter/lib/common/widgets/toolbar.dart: optional `actionId` field on
TToggleMenu / TRadioMenu, plus per-helper auto-register pass that wires
tagged entries' existing onChanged into the ShortcutModel
- flutter/test/keyboard_shortcuts_test.dart + fixtures: cross-language
parity (default bindings, supported key vocabulary)
Design principles applied during review:
1. Additions are fine; modifications to original logic must be deliberate.
Tagging an existing TToggleMenu entry with `actionId:` is an addition.
Rewriting its onChanged to satisfy a new contract is a modification —
and was reverted for every case where the original click behavior was
working. Four closures were touched and then reverted (mobile View
Mode, Privacy mode multi-impl, Relative mouse mode, Reverse mouse
wheel); their shortcuts are wired via standalone closures in
shortcut_model.dart instead.
2. Toolbar auto-register is reserved for entries whose onChanged is
inherently self-flipping — typically `sessionToggleOption(name)` where
the named option is flipped in place and the input bool is unused. The
register pass passes `!menu.value` from registration time, which is
harmless under self-flipping but wrong for closures that consume the
input bool directly. Tagging a non-self-flipping entry forces a closure
rewrite; choose non-toolbar registration in that case.
3. When shortcuts are disabled, toolbar behavior must be bit-for-bit
unchanged. The matcher's `enabled`-gate already guarantees no
dispatch; the auto-register pass is left unconditional (its only effect
is HashMap operations on a separate ShortcutModel) so mid-session
enable works without a reconnect. The trade-off is intentional and
documented at the top of toolbarControls.
4. Comments stay terse. Rationale lives in one place — the doc comment of
the helper or registration site, not duplicated at every call site.
5. Where an existing helper needs a new optional behavior (e.g.
`_OptionCheckBox` gaining a tooltip slot), the new branch must reduce
to byte-identical output for existing callers (`trailing == null`
case → original `Expanded(Text)` layout). Verified.
6. Action IDs and labels stay consistent. Renamed `reset_cursor` →
`reset_canvas` so the action ID matches its user-facing label
("Reset canvas") and capability flag.
Out-of-scope but included:
- AGENTS.md: documents flutter_rust_bridge no-codegen workflow and the
Web target's hand-written TS client, since both are load-bearing for
any new FFI work.
- remote_toolbar.dart: i18n fix for the per-monitor tooltip ("All
monitors" / "Monitor #N"), unrelated to shortcuts but kept here.
This commit is contained in:
@@ -23,7 +23,7 @@ use hbb_common::{
|
||||
sync::mpsc,
|
||||
time::{Duration as TokioDuration, Instant},
|
||||
},
|
||||
whoami, Stream,
|
||||
whoami, SessionID, Stream,
|
||||
};
|
||||
use rdev::{Event, EventType::*, KeyCode};
|
||||
#[cfg(all(feature = "vram", feature = "flutter"))]
|
||||
@@ -913,6 +913,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
#[cfg(any(target_os = "ios"))]
|
||||
pub fn handle_flutter_raw_key_event(
|
||||
&self,
|
||||
_session_id: SessionID,
|
||||
_keyboard_mode: &str,
|
||||
_name: &str,
|
||||
_platform_code: i32,
|
||||
@@ -925,6 +926,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
#[cfg(not(any(target_os = "ios")))]
|
||||
pub fn handle_flutter_raw_key_event(
|
||||
&self,
|
||||
session_id: SessionID,
|
||||
keyboard_mode: &str,
|
||||
name: &str,
|
||||
platform_code: i32,
|
||||
@@ -936,6 +938,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
self._handle_key_flutter_simulation(keyboard_mode, platform_code, down_or_up);
|
||||
} else {
|
||||
self._handle_raw_key_non_flutter_simulation(
|
||||
session_id,
|
||||
keyboard_mode,
|
||||
platform_code,
|
||||
position_code,
|
||||
@@ -948,6 +951,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
#[cfg(not(any(target_os = "ios")))]
|
||||
fn _handle_raw_key_non_flutter_simulation(
|
||||
&self,
|
||||
session_id: SessionID,
|
||||
keyboard_mode: &str,
|
||||
platform_code: i32,
|
||||
position_code: i32,
|
||||
@@ -981,11 +985,18 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
extra_data: 0,
|
||||
};
|
||||
keyboard::client::process_event_with_session(keyboard_mode, &event, Some(lock_modes), self);
|
||||
keyboard::client::process_event_with_session(
|
||||
keyboard_mode,
|
||||
&event,
|
||||
Some(lock_modes),
|
||||
self,
|
||||
session_id,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn handle_flutter_key_event(
|
||||
&self,
|
||||
session_id: SessionID,
|
||||
keyboard_mode: &str,
|
||||
character: &str,
|
||||
usb_hid: i32,
|
||||
@@ -996,6 +1007,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
self._handle_key_flutter_simulation(keyboard_mode, usb_hid, down_or_up);
|
||||
} else {
|
||||
self._handle_key_non_flutter_simulation(
|
||||
session_id,
|
||||
keyboard_mode,
|
||||
character,
|
||||
usb_hid,
|
||||
@@ -1031,6 +1043,7 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
|
||||
fn _handle_key_non_flutter_simulation(
|
||||
&self,
|
||||
session_id: SessionID,
|
||||
keyboard_mode: &str,
|
||||
character: &str,
|
||||
usb_hid: i32,
|
||||
@@ -1092,7 +1105,13 @@ impl<T: InvokeUiSession> Session<T> {
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
extra_data: 0,
|
||||
};
|
||||
keyboard::client::process_event_with_session(keyboard_mode, &event, Some(lock_modes), self);
|
||||
keyboard::client::process_event_with_session(
|
||||
keyboard_mode,
|
||||
&event,
|
||||
Some(lock_modes),
|
||||
self,
|
||||
session_id,
|
||||
);
|
||||
}
|
||||
|
||||
// flutter only TODO new input
|
||||
|
||||
Reference in New Issue
Block a user