mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-25 19:33:20 +03:00
Compare commits
1 Commits
v0.8.0
...
enter-hook
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9424abbd56 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1284,7 +1284,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse"
|
name = "lan-mouse"
|
||||||
version = "0.8.0"
|
version = "0.7.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"ashpd",
|
"ashpd",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lan-mouse"
|
name = "lan-mouse"
|
||||||
description = "Software KVM Switch / mouse & keyboard sharing software for Local Area Networks"
|
description = "Software KVM Switch / mouse & keyboard sharing software for Local Area Networks"
|
||||||
version = "0.8.0"
|
version = "0.7.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/ferdinandschober/lan-mouse"
|
repository = "https://github.com/ferdinandschober/lan-mouse"
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ struct State {
|
|||||||
qh: QueueHandle<Self>,
|
qh: QueueHandle<Self>,
|
||||||
pending_events: VecDeque<(ClientHandle, Event)>,
|
pending_events: VecDeque<(ClientHandle, Event)>,
|
||||||
output_info: Vec<(WlOutput, OutputInfo)>,
|
output_info: Vec<(WlOutput, OutputInfo)>,
|
||||||
scroll_discrete_pending: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Inner {
|
struct Inner {
|
||||||
@@ -352,7 +351,6 @@ impl WaylandInputCapture {
|
|||||||
read_guard: None,
|
read_guard: None,
|
||||||
pending_events: VecDeque::new(),
|
pending_events: VecDeque::new(),
|
||||||
output_info: vec![],
|
output_info: vec![],
|
||||||
scroll_discrete_pending: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// dispatch registry to () again, in order to read all wl_outputs
|
// dispatch registry to () again, in order to read all wl_outputs
|
||||||
@@ -754,25 +752,17 @@ impl Dispatch<WlPointer, ()> for State {
|
|||||||
}
|
}
|
||||||
wl_pointer::Event::Axis { time, axis, value } => {
|
wl_pointer::Event::Axis { time, axis, value } => {
|
||||||
let (_, client) = app.focused.as_ref().unwrap();
|
let (_, client) = app.focused.as_ref().unwrap();
|
||||||
if app.scroll_discrete_pending {
|
app.pending_events.push_back((
|
||||||
// each axisvalue120 event is coupled with
|
*client,
|
||||||
// a corresponding axis event, which needs to
|
Event::Pointer(PointerEvent::Axis {
|
||||||
// be ignored to not duplicate the scrolling
|
time,
|
||||||
app.scroll_discrete_pending = false;
|
axis: u32::from(axis) as u8,
|
||||||
} else {
|
value,
|
||||||
app.pending_events.push_back((
|
}),
|
||||||
*client,
|
));
|
||||||
Event::Pointer(PointerEvent::Axis {
|
|
||||||
time,
|
|
||||||
axis: u32::from(axis) as u8,
|
|
||||||
value,
|
|
||||||
}),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
wl_pointer::Event::AxisValue120 { axis, value120 } => {
|
wl_pointer::Event::AxisValue120 { axis, value120 } => {
|
||||||
let (_, client) = app.focused.as_ref().unwrap();
|
let (_, client) = app.focused.as_ref().unwrap();
|
||||||
app.scroll_discrete_pending = true;
|
|
||||||
app.pending_events.push_back((
|
app.pending_events.push_back((
|
||||||
*client,
|
*client,
|
||||||
Event::Pointer(PointerEvent::AxisDiscrete120 {
|
Event::Pointer(PointerEvent::AxisDiscrete120 {
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ fn to_mouse_event(wparam: WPARAM, lparam: LPARAM) -> Option<PointerEvent> {
|
|||||||
},
|
},
|
||||||
WPARAM(p) if p == WM_MOUSEWHEEL as usize => Some(PointerEvent::AxisDiscrete120 {
|
WPARAM(p) if p == WM_MOUSEWHEEL as usize => Some(PointerEvent::AxisDiscrete120 {
|
||||||
axis: 0,
|
axis: 0,
|
||||||
value: -(mouse_low_level.mouseData as i32 >> 16),
|
value: -(mouse_low_level.mouseData as i32),
|
||||||
}),
|
}),
|
||||||
WPARAM(p) if p == WM_XBUTTONDOWN as usize || p == WM_XBUTTONUP as usize => {
|
WPARAM(p) if p == WM_XBUTTONDOWN as usize || p == WM_XBUTTONUP as usize => {
|
||||||
let hb = mouse_low_level.mouseData >> 16;
|
let hb = mouse_low_level.mouseData >> 16;
|
||||||
|
|||||||
@@ -182,8 +182,7 @@ impl VirtualInput {
|
|||||||
}
|
}
|
||||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||||
let axis: Axis = (axis as u32).try_into()?;
|
let axis: Axis = (axis as u32).try_into()?;
|
||||||
self.pointer
|
self.pointer.axis(0, axis, (value / 15) as f64);
|
||||||
.axis_discrete(0, axis, value as f64 / 6., value / 120);
|
|
||||||
self.pointer.frame();
|
self.pointer.frame();
|
||||||
}
|
}
|
||||||
PointerEvent::Frame {} => self.pointer.frame(),
|
PointerEvent::Frame {} => self.pointer.frame(),
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input
|
* https://learn.microsoft.com/en-us/windows/win32/inputdev/about-keyboard-input
|
||||||
* https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
|
|
||||||
* https://kbd-project.org/docs/scancodes/scancodes-1.html
|
|
||||||
*/
|
*/
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
|
#[derive(Debug, Clone, Copy, TryFromPrimitive)]
|
||||||
@@ -122,15 +120,15 @@ pub enum Windows {
|
|||||||
KeyF21 = 0x006C,
|
KeyF21 = 0x006C,
|
||||||
KeyF22 = 0x006D,
|
KeyF22 = 0x006D,
|
||||||
KeyF23 = 0x006E,
|
KeyF23 = 0x006E,
|
||||||
KeyF24 = 0x0076, // KeyLANG5
|
KeyF24 = 0x0076,
|
||||||
KeypadComma = 0x007E,
|
KeypadComma = 0x007E,
|
||||||
KeyInternational1 = 0x0073,
|
KeyInternational1 = 0x0073,
|
||||||
KeyInternational2 = 0x0070,
|
KeyInternational2 = 0x0070,
|
||||||
KeyInternational3 = 0x007D, // typo in doc -> its Int'l 3 not Int'l 2
|
KeyInternational3 = 0x007D,
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
KeyInternational4 = 0x0079,
|
KeyInternational4 = 0x0079, // FIXME unused
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
KeyInternational5 = 0x007B,
|
KeyInternational5 = 0x007B, // FIXME unused
|
||||||
// KeyInternational6 = 0x005C,
|
// KeyInternational6 = 0x005C,
|
||||||
KeyLANG1 = 0x0072,
|
KeyLANG1 = 0x0072,
|
||||||
KeyLANG2 = 0x0071,
|
KeyLANG2 = 0x0071,
|
||||||
@@ -143,7 +141,6 @@ pub enum Windows {
|
|||||||
KeyLeftGUI = 0xE05B,
|
KeyLeftGUI = 0xE05B,
|
||||||
KeyRightCtrl = 0xE01D,
|
KeyRightCtrl = 0xE01D,
|
||||||
KeyRightShift = 0x0036,
|
KeyRightShift = 0x0036,
|
||||||
KeyFakeRightShift = 0xE036,
|
|
||||||
KeyRightAlt = 0xE038,
|
KeyRightAlt = 0xE038,
|
||||||
KeyRightGUI = 0xE05C,
|
KeyRightGUI = 0xE05C,
|
||||||
KeyScanNextTrack = 0xE019,
|
KeyScanNextTrack = 0xE019,
|
||||||
@@ -296,7 +293,7 @@ pub enum Linux {
|
|||||||
KeyPause = 119,
|
KeyPause = 119,
|
||||||
KeyScale = 120, /* AL Compiz Scale (Expose) */
|
KeyScale = 120, /* AL Compiz Scale (Expose) */
|
||||||
KeyKpcomma = 121,
|
KeyKpcomma = 121,
|
||||||
KeyHanguel = 122,
|
KeyHangeul = 122,
|
||||||
// KEY_HANGUEL = KeyHangeul,
|
// KEY_HANGUEL = KeyHangeul,
|
||||||
KeyHanja = 123,
|
KeyHanja = 123,
|
||||||
KeyYen = 124,
|
KeyYen = 124,
|
||||||
@@ -521,16 +518,16 @@ impl TryFrom<Linux> for Windows {
|
|||||||
Linux::KeyKp3 => Ok(Self::Keypad3PageDn),
|
Linux::KeyKp3 => Ok(Self::Keypad3PageDn),
|
||||||
Linux::KeyKp0 => Ok(Self::Keypad0Insert),
|
Linux::KeyKp0 => Ok(Self::Keypad0Insert),
|
||||||
Linux::KeyKpDot => Ok(Self::KeypadDot),
|
Linux::KeyKpDot => Ok(Self::KeypadDot),
|
||||||
Linux::KeyZenkakuhankaku => Ok(Self::KeyF24), // KeyLANG5
|
Linux::KeyZenkakuhankaku => Ok(Self::KeyLANG1), // TODO unsure
|
||||||
Linux::Key102nd => Ok(Self::KeyNonUSSlashBar), // TODO unsure
|
Linux::Key102nd => Ok(Self::KeyNonUSSlashBar), // TODO unsure
|
||||||
Linux::KeyF11 => Ok(Self::KeyF11),
|
Linux::KeyF11 => Ok(Self::KeyF11),
|
||||||
Linux::KeyF12 => Ok(Self::KeyF12),
|
Linux::KeyF12 => Ok(Self::KeyF12),
|
||||||
Linux::KeyRo => Ok(Self::KeyInternational1),
|
Linux::KeyRo => Ok(Self::ErrorRollOver), // TODO unsure
|
||||||
Linux::KeyKatakana => Ok(Self::KeyLANG3),
|
Linux::KeyKatakana => Ok(Self::KeyLANG1), // TODO unsure
|
||||||
Linux::KeyHiragana => Ok(Self::KeyLANG4),
|
Linux::KeyHiragana => Ok(Self::KeyLANG2), // TODO unsure
|
||||||
Linux::KeyHenkan => Ok(Self::KeyInternational4),
|
Linux::KeyHenkan => Ok(Self::KeyLANG3), // TODO unsure
|
||||||
Linux::KeyKatakanahiragana => Ok(Self::KeyInternational2),
|
Linux::KeyKatakanahiragana => Ok(Self::KeyLANG4), // TODO unsure
|
||||||
Linux::KeyMuhenkan => Ok(Self::KeyInternational5),
|
Linux::KeyMuhenkan => Ok(Self::KeyLANG4), // TODO unsure
|
||||||
Linux::KeyKpJpComma => Ok(Self::KeypadComma),
|
Linux::KeyKpJpComma => Ok(Self::KeypadComma),
|
||||||
Linux::KeyKpEnter => Ok(Self::KeypadEnter),
|
Linux::KeyKpEnter => Ok(Self::KeypadEnter),
|
||||||
Linux::KeyRightCtrl => Ok(Self::KeyRightCtrl),
|
Linux::KeyRightCtrl => Ok(Self::KeyRightCtrl),
|
||||||
@@ -558,9 +555,9 @@ impl TryFrom<Linux> for Windows {
|
|||||||
Linux::KeyPause => Ok(Self::KeyPause),
|
Linux::KeyPause => Ok(Self::KeyPause),
|
||||||
Linux::KeyScale => Err(()), // TODO
|
Linux::KeyScale => Err(()), // TODO
|
||||||
Linux::KeyKpcomma => Ok(Self::KeypadComma),
|
Linux::KeyKpcomma => Ok(Self::KeypadComma),
|
||||||
Linux::KeyHanguel => Ok(Self::KeyLANG1), // FIXME should be 00F2?
|
Linux::KeyHangeul => Ok(Self::KeyInternational1), // TODO unsure
|
||||||
Linux::KeyHanja => Ok(Self::KeyLANG2), // FIXME should be 00F1?
|
Linux::KeyHanja => Ok(Self::KeyInternational2), // TODO unsure
|
||||||
Linux::KeyYen => Ok(Self::KeyInternational3),
|
Linux::KeyYen => Ok(Self::KeyInternational3), // TODO unsure
|
||||||
Linux::KeyLeftMeta => Ok(Self::KeyLeftGUI),
|
Linux::KeyLeftMeta => Ok(Self::KeyLeftGUI),
|
||||||
Linux::KeyRightmeta => Ok(Self::KeyRightGUI),
|
Linux::KeyRightmeta => Ok(Self::KeyRightGUI),
|
||||||
Linux::KeyCompose => Ok(Self::KeyApplication),
|
Linux::KeyCompose => Ok(Self::KeyApplication),
|
||||||
@@ -810,22 +807,21 @@ impl TryFrom<Windows> for Linux {
|
|||||||
Windows::KeyF23 => Ok(Self::KeyF23),
|
Windows::KeyF23 => Ok(Self::KeyF23),
|
||||||
Windows::KeyF24 => Ok(Self::KeyF24),
|
Windows::KeyF24 => Ok(Self::KeyF24),
|
||||||
Windows::KeypadComma => Ok(Self::KeyKpcomma),
|
Windows::KeypadComma => Ok(Self::KeyKpcomma),
|
||||||
Windows::KeyInternational1 => Ok(Self::KeyRo),
|
Windows::KeyInternational1 => Ok(Self::KeyHangeul),
|
||||||
Windows::KeyInternational2 => Ok(Self::KeyKatakanahiragana),
|
Windows::KeyInternational2 => Ok(Self::KeyHanja),
|
||||||
Windows::KeyInternational3 => Ok(Self::KeyYen),
|
Windows::KeyInternational3 => Ok(Self::KeyYen),
|
||||||
Windows::KeyInternational4 => Ok(Self::KeyHenkan),
|
Windows::KeyInternational4 => Err(()),
|
||||||
Windows::KeyInternational5 => Ok(Self::KeyMuhenkan),
|
Windows::KeyInternational5 => Err(()),
|
||||||
Windows::KeyLANG1 => Ok(Self::KeyHanguel),
|
Windows::KeyLANG1 => Ok(Self::KeyKatakana),
|
||||||
Windows::KeyLANG2 => Ok(Self::KeyHanja),
|
Windows::KeyLANG2 => Ok(Self::KeyHiragana),
|
||||||
Windows::KeyLANG3 => Ok(Self::KeyKatakana),
|
Windows::KeyLANG3 => Ok(Self::KeyHenkan),
|
||||||
Windows::KeyLANG4 => Ok(Self::KeyHiragana),
|
Windows::KeyLANG4 => Ok(Self::KeyKatakanahiragana),
|
||||||
Windows::KeyLeftCtrl => Ok(Self::KeyLeftCtrl),
|
Windows::KeyLeftCtrl => Ok(Self::KeyLeftCtrl),
|
||||||
Windows::KeyLeftShift => Ok(Self::KeyLeftShift),
|
Windows::KeyLeftShift => Ok(Self::KeyLeftShift),
|
||||||
Windows::KeyLeftAlt => Ok(Self::KeyLeftAlt),
|
Windows::KeyLeftAlt => Ok(Self::KeyLeftAlt),
|
||||||
Windows::KeyLeftGUI => Ok(Self::KeyLeftMeta),
|
Windows::KeyLeftGUI => Ok(Self::KeyLeftMeta),
|
||||||
Windows::KeyRightCtrl => Ok(Self::KeyRightCtrl),
|
Windows::KeyRightCtrl => Ok(Self::KeyRightCtrl),
|
||||||
Windows::KeyRightShift => Ok(Self::KeyRightShift),
|
Windows::KeyRightShift => Ok(Self::KeyRightShift),
|
||||||
Windows::KeyFakeRightShift => Ok(Self::KeyRightShift),
|
|
||||||
Windows::KeyRightAlt => Ok(Self::KeyRightalt),
|
Windows::KeyRightAlt => Ok(Self::KeyRightalt),
|
||||||
Windows::KeyRightGUI => Ok(Self::KeyRightmeta),
|
Windows::KeyRightGUI => Ok(Self::KeyRightmeta),
|
||||||
Windows::KeyScanNextTrack => Ok(Self::KeyNextsong),
|
Windows::KeyScanNextTrack => Ok(Self::KeyNextsong),
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ async fn handle_frontend_event(
|
|||||||
log::debug!("frontend: {event:?}");
|
log::debug!("frontend: {event:?}");
|
||||||
match event {
|
match event {
|
||||||
FrontendRequest::Create => {
|
FrontendRequest::Create => {
|
||||||
let handle = add_client(server, frontend).await;
|
add_client(server, frontend).await;
|
||||||
resolve_dns(server, resolve_tx, handle).await;
|
|
||||||
}
|
}
|
||||||
FrontendRequest::Activate(handle, active) => {
|
FrontendRequest::Activate(handle, active) => {
|
||||||
if active {
|
if active {
|
||||||
@@ -141,12 +140,10 @@ async fn handle_frontend_event(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FrontendRequest::UpdateFixIps(handle, fix_ips) => {
|
FrontendRequest::UpdateFixIps(handle, fix_ips) => {
|
||||||
update_fix_ips(server, handle, fix_ips).await;
|
update_fix_ips(server, resolve_tx, handle, fix_ips).await;
|
||||||
resolve_dns(server, resolve_tx, handle).await;
|
|
||||||
}
|
}
|
||||||
FrontendRequest::UpdateHostname(handle, hostname) => {
|
FrontendRequest::UpdateHostname(handle, hostname) => {
|
||||||
update_hostname(server, resolve_tx, handle, hostname).await;
|
update_hostname(server, resolve_tx, handle, hostname).await;
|
||||||
resolve_dns(server, resolve_tx, handle).await;
|
|
||||||
}
|
}
|
||||||
FrontendRequest::UpdatePort(handle, port) => {
|
FrontendRequest::UpdatePort(handle, port) => {
|
||||||
update_port(server, handle, port).await;
|
update_port(server, handle, port).await;
|
||||||
@@ -155,41 +152,31 @@ async fn handle_frontend_event(
|
|||||||
update_pos(server, handle, capture, emulate, pos).await;
|
update_pos(server, handle, capture, emulate, pos).await;
|
||||||
}
|
}
|
||||||
FrontendRequest::ResolveDns(handle) => {
|
FrontendRequest::ResolveDns(handle) => {
|
||||||
resolve_dns(server, resolve_tx, handle).await;
|
let hostname = server
|
||||||
|
.client_manager
|
||||||
|
.borrow()
|
||||||
|
.get(handle)
|
||||||
|
.and_then(|(c, _)| c.hostname.clone());
|
||||||
|
if let Some(hostname) = hostname {
|
||||||
|
let _ = resolve_tx.send(DnsRequest { hostname, handle }).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve_dns(server: &Server, resolve_tx: &Sender<DnsRequest>, handle: ClientHandle) {
|
|
||||||
let hostname = server
|
|
||||||
.client_manager
|
|
||||||
.borrow()
|
|
||||||
.get(handle)
|
|
||||||
.and_then(|(c, _)| c.hostname.clone());
|
|
||||||
if let Some(hostname) = hostname {
|
|
||||||
let _ = resolve_tx
|
|
||||||
.send(DnsRequest {
|
|
||||||
hostname: hostname.clone(),
|
|
||||||
handle,
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn broadcast(frontend: &mut FrontendListener, event: FrontendEvent) {
|
async fn broadcast(frontend: &mut FrontendListener, event: FrontendEvent) {
|
||||||
if let Err(e) = frontend.broadcast_event(event).await {
|
if let Err(e) = frontend.broadcast_event(event).await {
|
||||||
log::error!("error notifying frontend: {e}");
|
log::error!("error notifying frontend: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn add_client(server: &Server, frontend: &mut FrontendListener) -> ClientHandle {
|
pub async fn add_client(server: &Server, frontend: &mut FrontendListener) {
|
||||||
let handle = server.client_manager.borrow_mut().add_client();
|
let handle = server.client_manager.borrow_mut().add_client();
|
||||||
log::info!("added client {handle}");
|
log::info!("added client {handle}");
|
||||||
|
|
||||||
let (c, s) = server.client_manager.borrow().get(handle).unwrap().clone();
|
let (c, s) = server.client_manager.borrow().get(handle).unwrap().clone();
|
||||||
broadcast(frontend, FrontendEvent::Created(handle, c, s)).await;
|
broadcast(frontend, FrontendEvent::Created(handle, c, s)).await;
|
||||||
handle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn deactivate_client(
|
pub async fn deactivate_client(
|
||||||
@@ -264,13 +251,25 @@ pub async fn remove_client(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_fix_ips(server: &Server, handle: ClientHandle, fix_ips: Vec<IpAddr>) {
|
async fn update_fix_ips(
|
||||||
let mut client_manager = server.client_manager.borrow_mut();
|
server: &Server,
|
||||||
let Some((c, _)) = client_manager.get_mut(handle) else {
|
resolve_tx: &Sender<DnsRequest>,
|
||||||
return;
|
handle: ClientHandle,
|
||||||
|
fix_ips: Vec<IpAddr>,
|
||||||
|
) {
|
||||||
|
let hostname = {
|
||||||
|
let mut client_manager = server.client_manager.borrow_mut();
|
||||||
|
let Some((c, _)) = client_manager.get_mut(handle) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
c.fix_ips = fix_ips;
|
||||||
|
c.hostname.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
c.fix_ips = fix_ips;
|
if let Some(hostname) = hostname {
|
||||||
|
let _ = resolve_tx.send(DnsRequest { hostname, handle }).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update_hostname(
|
async fn update_hostname(
|
||||||
|
|||||||
Reference in New Issue
Block a user