1use a7n_proto::v1::Platform;
6
7pub const LEFT_CTRL: u32 = 0x0007_00e0;
8pub const LEFT_META: u32 = 0x0007_00e3;
9pub const RIGHT_CTRL: u32 = 0x0007_00e4;
10pub const RIGHT_META: u32 = 0x0007_00e7;
11
12const CMD_CTRL_SWAP: &[(u32, u32)] = &[
13 (LEFT_META, LEFT_CTRL),
14 (LEFT_CTRL, LEFT_META),
15 (RIGHT_META, RIGHT_CTRL),
16 (RIGHT_CTRL, RIGHT_META),
17];
18
19#[must_use]
20pub fn default_modifier_remap(sender: Platform, receiver: Platform) -> &'static [(u32, u32)] {
21 match (sender, receiver) {
22 (Platform::Macos, Platform::Windows | Platform::Linux)
23 | (Platform::Windows | Platform::Linux, Platform::Macos) => CMD_CTRL_SWAP,
24 _ => &[],
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn default_modifier_remap_platform_pairs_swap_only_between_mac_and_pc() {
34 let platforms = [
36 Platform::Macos,
37 Platform::Windows,
38 Platform::Linux,
39 Platform::Unspecified,
40 ];
41 let expected_swap = [
42 (0x0007_00e3, 0x0007_00e0),
43 (0x0007_00e0, 0x0007_00e3),
44 (0x0007_00e7, 0x0007_00e4),
45 (0x0007_00e4, 0x0007_00e7),
46 ];
47 let swaps = [
48 [false, true, true, false],
49 [true, false, false, false],
50 [true, false, false, false],
51 [false, false, false, false],
52 ];
53 for (i, sender) in platforms.into_iter().enumerate() {
54 for (j, receiver) in platforms.into_iter().enumerate() {
55 let remap = default_modifier_remap(sender, receiver);
57
58 let expected = if swaps[i][j] {
60 expected_swap.as_slice()
61 } else {
62 &[]
63 };
64 assert_eq!(remap, expected, "{sender:?} → {receiver:?}");
65 }
66 }
67 }
68}