Skip to content

Commit fa56c97

Browse files
committed
added an option to change the mouse speed
1 parent 17670df commit fa56c97

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

Readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ During the first run the client will generate a config file called `inputshare-c
7171

7272
* `host_address`: The address of the raspberry pi that runs the sever
7373
* `hotkey`: The hotkey that toggles input between the local and remote pc. The hotkey has two parts: the trigger key which triggers the swap and a variable amount of modifier keys which also have to be pressed for the trigger to work. Supported values: [Possible key codes](#appendix-a-possible-key-codes).
74-
* `backlist`: All keys included in in this list will be ignored by the client. Supported values: [Possible key codes](#appendix-a-possible-key-codes).
74+
* `blacklist`: All keys included in in this list will be ignored by the client. Supported values: [Possible key codes](#appendix-a-possible-key-codes).
7575
* `show_network_info`: When set to `true` the client will display the round-trip-time and packet loss to the server. This call also be toggled at runtime by pressing `F1`.
7676
* `network_send_rate`: The number of packets per second that the client will send to the server while transmitting. Higher values mean lower latency and smoother mouse movement while lower values mean less network activity. Note that if the send rate is set to high it will flood the connection and cause massive delays / packet loss. Consider that the `mouse-tesselation-factor` option of the server has a similar effect and should be tuned in tandem.
77-
77+
* `mouse_speed_factor`: changes the mouse speed of the remote device
7878

7979

8080
### Server

inputshare-client/src/main.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn client() -> Result<()> {
128128
match event {
129129
ClientEvent::Connected(id) => {
130130
println!("Connected as {}", id);
131-
input_transmitter = Some(InputTransmitter::new(&config.hotkey, &config.backlist)?);
131+
input_transmitter = Some(InputTransmitter::new(&config)?);
132132
app.connect_button.set_text("Disconnect");
133133
app.connect_button.set_enabled(true);
134134
app.set_status(StatusText::Local);
@@ -191,8 +191,8 @@ struct InputTransmitter<'a> {
191191

192192
impl<'a> InputTransmitter<'a> {
193193

194-
fn new(hotkey: &Hotkey, blacklist: &HashSet<VirtualKey>) -> Result<Self> {
195-
let sender = Rc::new(RefCell::new(InputSender::new()));
194+
fn new(config: &Config) -> Result<Self> {
195+
let sender = Rc::new(RefCell::new(InputSender::new(config.mouse_speed_factor)));
196196
let hook = {
197197
let input_events = sender.clone();
198198
let mut old_mouse_pos = unsafe {
@@ -201,10 +201,10 @@ impl<'a> InputTransmitter<'a> {
201201
(point.x, point.y)
202202
};
203203

204-
let blacklist = blacklist.clone();
204+
let blacklist = config.blacklist.clone();
205+
let hotkey = config.hotkey.clone();
205206

206207
let mut captured = false;
207-
let hotkey = hotkey.clone();
208208
let mut pressed_keys = HashSet::new();
209209

210210
InputHook::new(move |event|{
@@ -418,17 +418,18 @@ impl<const N: usize> From<[VirtualKey; N]> for Hotkey {
418418
pub struct Config {
419419
pub host_address: String,
420420
pub hotkey: Hotkey,
421-
pub backlist: HashSet<VirtualKey>,
421+
pub blacklist: HashSet<VirtualKey>,
422422
pub show_network_info: bool,
423-
pub network_send_rate: u32
423+
pub network_send_rate: u32,
424+
pub mouse_speed_factor: f32
424425
}
425426

426427
impl Default for Config {
427428
fn default() -> Self {
428429
Self {
429430
host_address: String::from("raspberrypi.local:60067"),
430431
hotkey: Hotkey::from([VirtualKey::Apps]),
431-
backlist: HashSet::from([
432+
blacklist: HashSet::from([
432433
VirtualKey::VolumeDown,
433434
VirtualKey::VolumeUp,
434435
VirtualKey::VolumeMute,
@@ -438,7 +439,8 @@ impl Default for Config {
438439
VirtualKey::MediaNextTrack
439440
]),
440441
show_network_info: false,
441-
network_send_rate: 100
442+
network_send_rate: 100,
443+
mouse_speed_factor: 1.0
442444
}
443445
}
444446
}

inputshare-client/src/sender.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,38 @@ type MouseType = i64;
99
pub struct InputSender {
1010
packet_buffer: Vec<u8>,
1111
local_mouse_pos: Vec2<MouseType>,
12+
local_mouse_pos_raw: Vec2<MouseType>,
13+
mouse_speed_factor: f64,
1214
remote_mouse_pos: Vec2<MouseType>,
1315
message_queue: VecDeque<[u8; 2]>,
1416
last_message: u64
1517
}
1618

1719
impl InputSender {
1820

19-
pub fn new() -> Self {
21+
pub fn new(mouse_speed_factor: f32) -> Self {
2022
Self{
2123
packet_buffer: Vec::new(),
2224
local_mouse_pos: Vec2::new(0, 0),
25+
local_mouse_pos_raw: Vec2::new(0, 0),
26+
mouse_speed_factor: mouse_speed_factor.into(),
2327
remote_mouse_pos: Vec2::new(0, 0),
2428
message_queue: VecDeque::new(),
2529
last_message: 0
2630
}
2731
}
2832

2933
pub fn move_mouse(&mut self, x: MouseType, y: MouseType) {
30-
self.local_mouse_pos.x += x;
31-
self.local_mouse_pos.y += y;
34+
if (self.mouse_speed_factor - 1.0).abs() > f64::EPSILON {
35+
self.local_mouse_pos_raw.x += x;
36+
self.local_mouse_pos_raw.y += y;
37+
self.local_mouse_pos.x = f64::round(self.local_mouse_pos_raw.x as f64 * self.mouse_speed_factor) as MouseType;
38+
self.local_mouse_pos.y = f64::round(self.local_mouse_pos_raw.y as f64 * self.mouse_speed_factor) as MouseType;
39+
} else {
40+
self.local_mouse_pos.x += x;
41+
self.local_mouse_pos.y += y;
42+
}
43+
3244
}
3345

3446
pub fn reset(&mut self) {

0 commit comments

Comments
 (0)