mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-06-24 17:24:49 +03:00
Compare commits
15 Commits
move-featu
...
peer-versi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4bbf08ed66 | ||
|
|
63864a7fc9 | ||
|
|
9fb07a119f | ||
|
|
1c92d9c5c7 | ||
|
|
3b7570c062 | ||
|
|
59b6447745 | ||
|
|
dbeaea03ad | ||
|
|
0d2190e787 | ||
|
|
4b93be3228 | ||
|
|
c32d695cd9 | ||
|
|
82d677f9c8 | ||
|
|
7ef43418c9 | ||
|
|
8f32b7fe96 | ||
|
|
02ac0bf220 | ||
|
|
1b53e58ba9 |
7
.github/workflows/release.yml
vendored
7
.github/workflows/release.yml
vendored
@@ -174,13 +174,16 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Download build artifacts
|
- name: Download build artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
- name: Get short SHA
|
||||||
|
id: vars
|
||||||
|
run: echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
|
||||||
- name: Create Pre-Release
|
- name: Create Pre-Release
|
||||||
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
tag_name: ${{ github.event.inputs.name || github.ref_name }}
|
tag_name: ${{ format('{0}-{1}', github.event.inputs.name || github.ref_name, steps.vars.outputs.short_sha) }}
|
||||||
name: ${{ github.event.inputs.name || github.ref_name }}
|
name: ${{ format('{0}-{1}', github.event.inputs.name || github.ref_name, steps.vars.outputs.short_sha) }}
|
||||||
prerelease: true
|
prerelease: true
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
files: |
|
files: |
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ Lan Mouse is an open-source Software KVM sharing mouse/keyboard input across loc
|
|||||||
|
|
||||||
## Feature & cfg discipline
|
## Feature & cfg discipline
|
||||||
|
|
||||||
- Feature flags live in root `Cargo.toml`. Gate OS-specific modules with tight cfgs (e.g., `cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))`).
|
- Feature flags live in root `Cargo.toml`. Gate OS-specific modules with the configs exported in build.rs (e.g., `cfg(layer_shell)`).
|
||||||
- Prefer module-level gating over per-function cfgs to avoid empty stubs.
|
- Prefer module-level gating over per-function cfgs to avoid empty stubs.
|
||||||
- New backends: add feature in `Cargo.toml`, create gated module, log backend selection.
|
- New backends: add feature in `Cargo.toml`, create gated module, log backend selection.
|
||||||
|
|
||||||
|
|||||||
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -1647,7 +1647,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "input-capture"
|
name = "input-capture"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ashpd",
|
"ashpd",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -1677,7 +1677,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "input-emulation"
|
name = "input-emulation"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ashpd",
|
"ashpd",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -1703,7 +1703,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "input-event"
|
name = "input-event"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"log",
|
"log",
|
||||||
@@ -1840,7 +1840,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse"
|
name = "lan-mouse"
|
||||||
version = "0.10.0"
|
version = "0.11.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
@@ -1875,7 +1875,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse-cli"
|
name = "lan-mouse-cli"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"futures",
|
"futures",
|
||||||
@@ -1886,7 +1886,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse-gtk"
|
name = "lan-mouse-gtk"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"glib-build-tools",
|
"glib-build-tools",
|
||||||
@@ -1900,7 +1900,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse-ipc"
|
name = "lan-mouse-ipc"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"log",
|
"log",
|
||||||
@@ -1913,7 +1913,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lan-mouse-proto"
|
name = "lan-mouse-proto"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"input-event",
|
"input-event",
|
||||||
"num_enum",
|
"num_enum",
|
||||||
|
|||||||
16
Cargo.toml
16
Cargo.toml
@@ -12,7 +12,7 @@ members = [
|
|||||||
[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.10.0"
|
version = "0.11.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
@@ -27,13 +27,13 @@ panic = "abort"
|
|||||||
shadow-rs = "1.2.0"
|
shadow-rs = "1.2.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
input-event = { path = "input-event", version = "0.3.0" }
|
input-event = { path = "input-event", version = "0.4.0" }
|
||||||
input-emulation = { path = "input-emulation", version = "0.3.0", default-features = false }
|
input-emulation = { path = "input-emulation", version = "0.4.0", default-features = false }
|
||||||
input-capture = { path = "input-capture", version = "0.3.0", default-features = false }
|
input-capture = { path = "input-capture", version = "0.4.0", default-features = false }
|
||||||
lan-mouse-cli = { path = "lan-mouse-cli", version = "0.2.0" }
|
lan-mouse-cli = { path = "lan-mouse-cli", version = "0.3.0" }
|
||||||
lan-mouse-gtk = { path = "lan-mouse-gtk", version = "0.2.0", optional = true }
|
lan-mouse-gtk = { path = "lan-mouse-gtk", version = "0.3.0", optional = true }
|
||||||
lan-mouse-ipc = { path = "lan-mouse-ipc", version = "0.2.0" }
|
lan-mouse-ipc = { path = "lan-mouse-ipc", version = "0.3.0" }
|
||||||
lan-mouse-proto = { path = "lan-mouse-proto", version = "0.2.0" }
|
lan-mouse-proto = { path = "lan-mouse-proto", version = "0.3.0" }
|
||||||
shadow-rs = { version = "1.2.0", features = ["metadata"] }
|
shadow-rs = { version = "1.2.0", features = ["metadata"] }
|
||||||
|
|
||||||
hickory-resolver = "0.25.2"
|
hickory-resolver = "0.25.2"
|
||||||
|
|||||||
53
build.rs
53
build.rs
@@ -5,4 +5,57 @@ fn main() {
|
|||||||
.deny_const(Default::default())
|
.deny_const(Default::default())
|
||||||
.build()
|
.build()
|
||||||
.expect("shadow build");
|
.expect("shadow build");
|
||||||
|
|
||||||
|
let unix = cfg!(unix);
|
||||||
|
let macos = cfg!(target_os = "macos");
|
||||||
|
|
||||||
|
let layer_shell_capture = cfg!(feature = "layer_shell_capture");
|
||||||
|
let libei_capture = cfg!(feature = "libei_capture");
|
||||||
|
let x11_capture = cfg!(feature = "x11_capture");
|
||||||
|
|
||||||
|
let libei_emulation = cfg!(feature = "libei_emulation");
|
||||||
|
let x11_emulation = cfg!(feature = "x11_emulation");
|
||||||
|
let wlroots_emulation = cfg!(feature = "wlroots_emulation");
|
||||||
|
let rdp_emulation = cfg!(feature = "rdp_emulation");
|
||||||
|
|
||||||
|
let layer_shell_capture = unix && !macos && layer_shell_capture;
|
||||||
|
let libei_capture = unix && !macos && libei_capture;
|
||||||
|
let x11_capture = unix && !macos && x11_capture;
|
||||||
|
|
||||||
|
let libei_emulation = unix && !macos && libei_emulation;
|
||||||
|
let rdp_emulation = unix && !macos && rdp_emulation;
|
||||||
|
let wlroots_emulation = unix && !macos && wlroots_emulation;
|
||||||
|
let x11_emulation = unix && !macos && x11_emulation;
|
||||||
|
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(layer_shell_capture)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(libei_capture)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(x11_capture)");
|
||||||
|
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(libei_emulation)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(rdp_emulation)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(wlroots_emulation)");
|
||||||
|
println!("cargo::rustc-check-cfg=cfg(x11_emulation)");
|
||||||
|
|
||||||
|
if layer_shell_capture {
|
||||||
|
println!("cargo::rustc-cfg=layer_shell_capture");
|
||||||
|
}
|
||||||
|
if libei_capture {
|
||||||
|
println!("cargo::rustc-cfg=libei_capture");
|
||||||
|
}
|
||||||
|
if x11_capture {
|
||||||
|
println!("cargo::rustc-cfg=x11_capture");
|
||||||
|
}
|
||||||
|
|
||||||
|
if libei_emulation {
|
||||||
|
println!("cargo::rustc-cfg=libei_emulation");
|
||||||
|
}
|
||||||
|
if rdp_emulation {
|
||||||
|
println!("cargo::rustc-cfg=rdp_emulation");
|
||||||
|
}
|
||||||
|
if wlroots_emulation {
|
||||||
|
println!("cargo::rustc-cfg=wlroots_emulation");
|
||||||
|
}
|
||||||
|
if x11_emulation {
|
||||||
|
println!("cargo::rustc-cfg=x11_emulation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "input-capture"
|
name = "input-capture"
|
||||||
description = "cross-platform input-capture library used by lan-mouse"
|
description = "cross-platform input-capture library used by lan-mouse"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
@@ -10,7 +10,7 @@ repository = "https://github.com/feschber/lan-mouse"
|
|||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
futures-core = "0.3.30"
|
futures-core = "0.3.30"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
input-event = { path = "../input-event", version = "0.3.0" }
|
input-event = { path = "../input-event", version = "0.4.0" }
|
||||||
memmap = "0.7"
|
memmap = "0.7"
|
||||||
tempfile = "3.25.0"
|
tempfile = "3.25.0"
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "input-emulation"
|
name = "input-emulation"
|
||||||
description = "cross-platform input emulation library used by lan-mouse"
|
description = "cross-platform input emulation library used by lan-mouse"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
@@ -10,7 +10,7 @@ repository = "https://github.com/feschber/lan-mouse"
|
|||||||
async-trait = "0.1.80"
|
async-trait = "0.1.80"
|
||||||
futures = "0.3.28"
|
futures = "0.3.28"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
input-event = { path = "../input-event", version = "0.3.0" }
|
input-event = { path = "../input-event", version = "0.4.0" }
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
tokio = { version = "1.32.0", features = [
|
tokio = { version = "1.32.0", features = [
|
||||||
"io-util",
|
"io-util",
|
||||||
|
|||||||
@@ -106,8 +106,19 @@ impl MacOSEmulation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// release key when cancelled
|
// Always release the key with the correct CGKeyCode, regardless of
|
||||||
update_modifiers(&modifiers, key as u32, 0);
|
// whether the repeat loop ran. This matches @feschber's review
|
||||||
|
// request: "still release the key repeat task but with the correct
|
||||||
|
// code."
|
||||||
|
//
|
||||||
|
// Do NOT call update_modifiers here: `key` is a Mac CGKeyCode but
|
||||||
|
// update_modifiers expects a Linux evdev scancode, and the two
|
||||||
|
// codespaces collide (e.g. Mac LeftShift=56 == Linux KeyLeftAlt=56,
|
||||||
|
// Mac Down=125 == Linux KeyLeftMeta=125), corrupting modifier
|
||||||
|
// state for chords like Shift+Option+X or Cmd+Down. Modifier state
|
||||||
|
// is owned by the main consume() loop, which already calls
|
||||||
|
// update_modifiers with the correct Linux scancode on the real key
|
||||||
|
// release event from the client.
|
||||||
key_event(event_source.clone(), key, 0, modifiers.get());
|
key_event(event_source.clone(), key, 0, modifiers.get());
|
||||||
});
|
});
|
||||||
self.repeat_task = Some(repeat_task);
|
self.repeat_task = Some(repeat_task);
|
||||||
@@ -157,6 +168,19 @@ extern "C" {
|
|||||||
fn AXIsProcessTrusted() -> bool;
|
fn AXIsProcessTrusted() -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Mac virtual key codes for the four arrow keys.
|
||||||
|
const MAC_KEY_LEFT: u16 = 0x7B;
|
||||||
|
const MAC_KEY_RIGHT: u16 = 0x7C;
|
||||||
|
const MAC_KEY_DOWN: u16 = 0x7D;
|
||||||
|
const MAC_KEY_UP: u16 = 0x7E;
|
||||||
|
|
||||||
|
fn is_arrow_key(key: u16) -> bool {
|
||||||
|
matches!(
|
||||||
|
key,
|
||||||
|
MAC_KEY_LEFT | MAC_KEY_RIGHT | MAC_KEY_DOWN | MAC_KEY_UP
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn key_event(event_source: CGEventSource, key: u16, state: u8, modifiers: XMods) {
|
fn key_event(event_source: CGEventSource, key: u16, state: u8, modifiers: XMods) {
|
||||||
let event = match CGEvent::new_keyboard_event(event_source, key, state != 0) {
|
let event = match CGEvent::new_keyboard_event(event_source, key, state != 0) {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
@@ -165,7 +189,15 @@ fn key_event(event_source: CGEventSource, key: u16, state: u8, modifiers: XMods)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
event.set_flags(to_cgevent_flags(modifiers));
|
let mut flags = to_cgevent_flags(modifiers);
|
||||||
|
// Hardware-generated arrow keys on macOS carry NumericPad + SecondaryFn.
|
||||||
|
// CGEventTap-based hotkey matchers (e.g. tiling window managers) check
|
||||||
|
// these flags to recognize navigation keys; without them synthesized
|
||||||
|
// arrow chords fall through to the focused app.
|
||||||
|
if is_arrow_key(key) {
|
||||||
|
flags |= CGEventFlags::CGEventFlagNumericPad | CGEventFlags::CGEventFlagSecondaryFn;
|
||||||
|
}
|
||||||
|
event.set_flags(flags);
|
||||||
event.post(CGEventTapLocation::HID);
|
event.post(CGEventTapLocation::HID);
|
||||||
log::trace!("key event: {key} {state}");
|
log::trace!("key event: {key} {state}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "input-event"
|
name = "input-event"
|
||||||
description = "cross-platform input-event types for input-capture / input-emulation"
|
description = "cross-platform input-event types for input-capture / input-emulation"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lan-mouse-cli"
|
name = "lan-mouse-cli"
|
||||||
description = "CLI Frontend for lan-mouse"
|
description = "CLI Frontend for lan-mouse"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
|
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.3.0" }
|
||||||
clap = { version = "4.4.11", features = ["derive"] }
|
clap = { version = "4.4.11", features = ["derive"] }
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
tokio = { version = "1.32.0", features = [
|
tokio = { version = "1.32.0", features = [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lan-mouse-gtk"
|
name = "lan-mouse-gtk"
|
||||||
description = "GTK4 / Libadwaita Frontend for lan-mouse"
|
description = "GTK4 / Libadwaita Frontend for lan-mouse"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
@@ -12,7 +12,7 @@ adw = { package = "libadwaita", version = "0.7.0", features = ["v1_1"] }
|
|||||||
async-channel = { version = "2.1.1" }
|
async-channel = { version = "2.1.1" }
|
||||||
hostname = "0.4.0"
|
hostname = "0.4.0"
|
||||||
log = "0.4.20"
|
log = "0.4.20"
|
||||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
|
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.3.0" }
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<file compressed="true" preprocess="xml-stripblanks">fingerprint_window.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">fingerprint_window.ui</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">client_row.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">client_row.ui</file>
|
||||||
<file compressed="true" preprocess="xml-stripblanks">key_row.ui</file>
|
<file compressed="true" preprocess="xml-stripblanks">key_row.ui</file>
|
||||||
|
<file compressed="true">style.css</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
<gresource prefix="/de/feschber/LanMouse/icons">
|
<gresource prefix="/de/feschber/LanMouse/icons">
|
||||||
<file compressed="true" preprocess="xml-stripblanks">de.feschber.LanMouse.svg</file>
|
<file compressed="true" preprocess="xml-stripblanks">de.feschber.LanMouse.svg</file>
|
||||||
|
|||||||
12
lan-mouse-gtk/resources/style.css
Normal file
12
lan-mouse-gtk/resources/style.css
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
.peer-match > box > list .subtitle {
|
||||||
|
color: @success_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.peer-mismatch > box > list .subtitle {
|
||||||
|
font-weight: bold;
|
||||||
|
color: @warning_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
.peer-unknown > box > list .subtitle {
|
||||||
|
color: @warning_color;
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ impl ClientObject {
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.property("resolving", state.resolving)
|
.property("resolving", state.resolving)
|
||||||
|
.property("peer-commit", peer_commit_to_string(state.peer_commit))
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +35,14 @@ impl ClientObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Render the 8-byte ASCII commit hash carried in
|
||||||
|
/// [`lan_mouse_ipc::ClientState::peer_commit`] as a `String`. `None`
|
||||||
|
/// in → `None` out (peer hasn't sent a Hello yet, or speaks an older
|
||||||
|
/// proto).
|
||||||
|
pub fn peer_commit_to_string(commit: Option<[u8; 8]>) -> Option<String> {
|
||||||
|
commit.and_then(|c| std::str::from_utf8(&c).ok().map(str::to_string))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct ClientData {
|
pub struct ClientData {
|
||||||
pub handle: ClientHandle,
|
pub handle: ClientHandle,
|
||||||
@@ -43,4 +52,5 @@ pub struct ClientData {
|
|||||||
pub position: String,
|
pub position: String,
|
||||||
pub resolving: bool,
|
pub resolving: bool,
|
||||||
pub ips: Vec<String>,
|
pub ips: Vec<String>,
|
||||||
|
pub peer_commit: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ pub struct ClientObject {
|
|||||||
#[property(name = "position", get, set, type = String, member = position)]
|
#[property(name = "position", get, set, type = String, member = position)]
|
||||||
#[property(name = "resolving", get, set, type = bool, member = resolving)]
|
#[property(name = "resolving", get, set, type = bool, member = resolving)]
|
||||||
#[property(name = "ips", get, set, type = Vec<String>, member = ips)]
|
#[property(name = "ips", get, set, type = Vec<String>, member = ips)]
|
||||||
|
#[property(name = "peer-commit", get, set, type = Option<String>, member = peer_commit)]
|
||||||
pub data: RefCell<ClientData>,
|
pub data: RefCell<ClientData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,12 @@ impl ClientRow {
|
|||||||
bindings.push(position_binding);
|
bindings.push(position_binding);
|
||||||
bindings.push(resolve_binding);
|
bindings.push(resolve_binding);
|
||||||
bindings.push(ip_binding);
|
bindings.push(ip_binding);
|
||||||
|
|
||||||
|
// Render the initial collapsed subtitle from whatever
|
||||||
|
// peer_commit the ClientObject was created with. Subsequent
|
||||||
|
// changes are pushed by `Window::update_client_state` calling
|
||||||
|
// `refresh_version_status` after writing the new property.
|
||||||
|
self.refresh_version_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unbind(&self) {
|
pub fn unbind(&self) {
|
||||||
@@ -150,4 +156,40 @@ impl ClientRow {
|
|||||||
pub fn set_dns_state(&self, resolved: bool) {
|
pub fn set_dns_state(&self, resolved: bool) {
|
||||||
self.imp().set_dns_state(resolved);
|
self.imp().set_dns_state(resolved);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recompute the collapsed subtitle (Pango markup) based on the
|
||||||
|
/// current `peer-commit` property and the local build's commit.
|
||||||
|
/// Soft-warn semantics: a missing or mismatched peer commit
|
||||||
|
/// surfaces as orange text but never blocks traffic. Called by
|
||||||
|
/// the window after `update_client_state` writes the new
|
||||||
|
/// `peer-commit`. The dns-status icon is left to its existing
|
||||||
|
/// `set_dns_state` handler so the two indicators don't fight
|
||||||
|
/// for the same CSS class.
|
||||||
|
pub fn refresh_version_status(&self) {
|
||||||
|
let peer: Option<String> = self
|
||||||
|
.imp()
|
||||||
|
.client_object
|
||||||
|
.borrow()
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|co| co.property::<Option<String>>("peer-commit"));
|
||||||
|
let local = crate::local_commit_str();
|
||||||
|
let markup = match peer.as_deref() {
|
||||||
|
None => format!("Peer version: unknown · Ours: {local}"),
|
||||||
|
Some(p) if p == local.as_str() => {
|
||||||
|
format!("Peer version: {p} · matched")
|
||||||
|
}
|
||||||
|
Some(p) => {
|
||||||
|
format!("Peer version: {p} · Ours: {local}")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
self.remove_css_class("peer-mismatch");
|
||||||
|
self.remove_css_class("peer-match");
|
||||||
|
self.remove_css_class("peer-unknown");
|
||||||
|
match peer.as_deref() {
|
||||||
|
Some(p) if p == local.as_str() => self.add_css_class("peer-match"),
|
||||||
|
Some(_) => self.add_css_class("peer-mismatch"),
|
||||||
|
None => self.add_css_class("peer-unknown"),
|
||||||
|
};
|
||||||
|
self.set_subtitle(&markup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,28 @@ mod macos_privacy;
|
|||||||
mod macos_status_item;
|
mod macos_status_item;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use std::{env, process, str};
|
use std::{env, process, str, sync::OnceLock};
|
||||||
|
|
||||||
|
use gtk::CssProvider;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
|
/// Local build's commit hash, set once by [`run`] before the GTK
|
||||||
|
/// main loop starts. Read by per-row UI to compare against each
|
||||||
|
/// peer's [`lan_mouse_ipc::ClientState::peer_commit`] for the
|
||||||
|
/// soft-warn version-mismatch indicator.
|
||||||
|
pub(crate) static LOCAL_COMMIT: OnceLock<[u8; 8]> = OnceLock::new();
|
||||||
|
|
||||||
|
/// Convenience: returns the local commit as an 8-char ASCII string,
|
||||||
|
/// or a placeholder if unset (which would indicate a programmer
|
||||||
|
/// error since [`run`] always sets it).
|
||||||
|
pub(crate) fn local_commit_str() -> String {
|
||||||
|
LOCAL_COMMIT
|
||||||
|
.get()
|
||||||
|
.and_then(|c| std::str::from_utf8(c).ok())
|
||||||
|
.unwrap_or("????????")
|
||||||
|
.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
use lan_mouse_ipc::FrontendEvent;
|
use lan_mouse_ipc::FrontendEvent;
|
||||||
|
|
||||||
use adw::Application;
|
use adw::Application;
|
||||||
@@ -31,8 +49,12 @@ pub enum GtkError {
|
|||||||
NonZeroExitCode(i32),
|
NonZeroExitCode(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run() -> Result<(), GtkError> {
|
pub fn run(local_commit: [u8; 8]) -> Result<(), GtkError> {
|
||||||
log::debug!("running gtk frontend");
|
log::debug!("running gtk frontend");
|
||||||
|
LOCAL_COMMIT
|
||||||
|
.set(local_commit)
|
||||||
|
.expect("local_commit set once");
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
let ret = std::thread::Builder::new()
|
let ret = std::thread::Builder::new()
|
||||||
.stack_size(8 * 1024 * 1024) // https://gitlab.gnome.org/GNOME/gtk/-/commit/52dbb3f372b2c3ea339e879689c1de535ba2c2c3 -> caused crash on windows
|
.stack_size(8 * 1024 * 1024) // https://gitlab.gnome.org/GNOME/gtk/-/commit/52dbb3f372b2c3ea339e879689c1de535ba2c2c3 -> caused crash on windows
|
||||||
@@ -64,6 +86,7 @@ fn gtk_main() -> glib::ExitCode {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
app.connect_startup(|app| {
|
app.connect_startup(|app| {
|
||||||
|
load_css();
|
||||||
load_icons();
|
load_icons();
|
||||||
setup_actions(app);
|
setup_actions(app);
|
||||||
setup_menu(app);
|
setup_menu(app);
|
||||||
@@ -132,6 +155,16 @@ fn configure_macos_bundle_environment() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn load_css() {
|
||||||
|
let provider = CssProvider::default();
|
||||||
|
provider.load_from_resource("de/feschber/LanMouse/style.css");
|
||||||
|
gtk::style_context_add_provider_for_display(
|
||||||
|
&Display::default().expect("Could not connect to a display"),
|
||||||
|
&provider,
|
||||||
|
gtk::STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn load_icons() {
|
fn load_icons() {
|
||||||
let display = &Display::default().expect("Could not connect to a display.");
|
let display = &Display::default().expect("Could not connect to a display.");
|
||||||
let icon_theme = IconTheme::for_display(display);
|
let icon_theme = IconTheme::for_display(display);
|
||||||
|
|||||||
@@ -365,6 +365,13 @@ impl Window {
|
|||||||
.map(|ip| ip.to_string())
|
.map(|ip| ip.to_string())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
client_object.set_ips(ips);
|
client_object.set_ips(ips);
|
||||||
|
|
||||||
|
/* peer build version (drives the version-match indicator) */
|
||||||
|
client_object.set_property(
|
||||||
|
"peer-commit",
|
||||||
|
crate::client_object::peer_commit_to_string(state.peer_commit),
|
||||||
|
);
|
||||||
|
row.refresh_version_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn client_object_for_handle(&self, handle: ClientHandle) -> Option<ClientObject> {
|
fn client_object_for_handle(&self, handle: ClientHandle) -> Option<ClientObject> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lan-mouse-ipc"
|
name = "lan-mouse-ipc"
|
||||||
description = "library for communication between lan-mouse service and frontends"
|
description = "library for communication between lan-mouse service and frontends"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
|
|||||||
@@ -176,6 +176,12 @@ pub struct ClientState {
|
|||||||
pub has_pressed_keys: bool,
|
pub has_pressed_keys: bool,
|
||||||
/// dns resolving in progress
|
/// dns resolving in progress
|
||||||
pub resolving: bool,
|
pub resolving: bool,
|
||||||
|
/// Peer's build short commit hash from the [`Hello`] proto
|
||||||
|
/// event. `None` means we haven't received a Hello yet — either
|
||||||
|
/// the connection is fresh, or the peer is on an older build
|
||||||
|
/// that predates the Hello event. The frontend uses this to
|
||||||
|
/// soft-warn on version mismatch.
|
||||||
|
pub peer_commit: Option<[u8; 8]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lan-mouse-proto"
|
name = "lan-mouse-proto"
|
||||||
description = "network protocol for lan-mouse"
|
description = "network protocol for lan-mouse"
|
||||||
version = "0.2.0"
|
version = "0.3.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
repository = "https://github.com/feschber/lan-mouse"
|
repository = "https://github.com/feschber/lan-mouse"
|
||||||
@@ -9,5 +9,5 @@ repository = "https://github.com/feschber/lan-mouse"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
num_enum = "0.7.2"
|
num_enum = "0.7.2"
|
||||||
thiserror = "2.0.0"
|
thiserror = "2.0.0"
|
||||||
input-event = { path = "../input-event", version = "0.3.0" }
|
input-event = { path = "../input-event", version = "0.4.0" }
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
|
|||||||
@@ -63,6 +63,15 @@ pub enum ProtoEvent {
|
|||||||
Ping,
|
Ping,
|
||||||
/// Response to [`ProtoEvent::Ping`], true if emulation is enabled / available
|
/// Response to [`ProtoEvent::Ping`], true if emulation is enabled / available
|
||||||
Pong(bool),
|
Pong(bool),
|
||||||
|
/// Build identification for the sending peer. Sent by the
|
||||||
|
/// connect side once after the connection authenticates, and
|
||||||
|
/// echoed back by the listen side in reply, so each end can
|
||||||
|
/// display the peer's build hash and warn (soft) on mismatch.
|
||||||
|
/// `commit` is the 8-byte ASCII short commit hash from
|
||||||
|
/// `shadow_rs`'s `SHORT_COMMIT`. Old peers that don't
|
||||||
|
/// recognize the event type silently skip it per the
|
||||||
|
/// forward-compat handling in the receive loop.
|
||||||
|
Hello { commit: [u8; 8] },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for ProtoEvent {
|
impl Display for ProtoEvent {
|
||||||
@@ -80,6 +89,10 @@ impl Display for ProtoEvent {
|
|||||||
if *alive { "alive" } else { "not available" }
|
if *alive { "alive" } else { "not available" }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
ProtoEvent::Hello { commit } => {
|
||||||
|
let s = std::str::from_utf8(commit).unwrap_or("????????");
|
||||||
|
write!(f, "Hello({s})")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +111,7 @@ pub enum EventType {
|
|||||||
Enter,
|
Enter,
|
||||||
Leave,
|
Leave,
|
||||||
Ack,
|
Ack,
|
||||||
|
Hello,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProtoEvent {
|
impl ProtoEvent {
|
||||||
@@ -120,6 +134,7 @@ impl ProtoEvent {
|
|||||||
ProtoEvent::Enter(_) => EventType::Enter,
|
ProtoEvent::Enter(_) => EventType::Enter,
|
||||||
ProtoEvent::Leave(_) => EventType::Leave,
|
ProtoEvent::Leave(_) => EventType::Leave,
|
||||||
ProtoEvent::Ack(_) => EventType::Ack,
|
ProtoEvent::Ack(_) => EventType::Ack,
|
||||||
|
ProtoEvent::Hello { .. } => EventType::Hello,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,6 +189,13 @@ impl TryFrom<[u8; MAX_EVENT_SIZE]> for ProtoEvent {
|
|||||||
EventType::Enter => Ok(Self::Enter(decode_u8(&mut buf)?.try_into()?)),
|
EventType::Enter => Ok(Self::Enter(decode_u8(&mut buf)?.try_into()?)),
|
||||||
EventType::Leave => Ok(Self::Leave(decode_u32(&mut buf)?)),
|
EventType::Leave => Ok(Self::Leave(decode_u32(&mut buf)?)),
|
||||||
EventType::Ack => Ok(Self::Ack(decode_u32(&mut buf)?)),
|
EventType::Ack => Ok(Self::Ack(decode_u32(&mut buf)?)),
|
||||||
|
EventType::Hello => {
|
||||||
|
let mut commit = [0u8; 8];
|
||||||
|
for b in commit.iter_mut() {
|
||||||
|
*b = decode_u8(&mut buf)?;
|
||||||
|
}
|
||||||
|
Ok(Self::Hello { commit })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,6 +260,11 @@ impl From<ProtoEvent> for ([u8; MAX_EVENT_SIZE], usize) {
|
|||||||
ProtoEvent::Enter(pos) => encode_u8(buf, len, pos as u8),
|
ProtoEvent::Enter(pos) => encode_u8(buf, len, pos as u8),
|
||||||
ProtoEvent::Leave(serial) => encode_u32(buf, len, serial),
|
ProtoEvent::Leave(serial) => encode_u32(buf, len, serial),
|
||||||
ProtoEvent::Ack(serial) => encode_u32(buf, len, serial),
|
ProtoEvent::Ack(serial) => encode_u32(buf, len, serial),
|
||||||
|
ProtoEvent::Hello { commit } => {
|
||||||
|
for b in commit.iter() {
|
||||||
|
encode_u8(buf, len, *b);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(buf, len)
|
(buf, len)
|
||||||
|
|||||||
@@ -282,6 +282,12 @@ impl ClientManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_peer_commit(&self, handle: ClientHandle, commit: Option<[u8; 8]>) {
|
||||||
|
if let Some((_, s)) = self.clients.borrow_mut().get_mut(handle as usize) {
|
||||||
|
s.peer_commit = commit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn active_addr(&self, handle: ClientHandle) -> Option<SocketAddr> {
|
pub(crate) fn active_addr(&self, handle: ClientHandle) -> Option<SocketAddr> {
|
||||||
self.clients
|
self.clients
|
||||||
.borrow()
|
.borrow()
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::capture_test::TestCaptureArgs;
|
use crate::capture_test::TestCaptureArgs;
|
||||||
use crate::emulation_test::TestEmulationArgs;
|
use crate::emulation_test::TestEmulationArgs;
|
||||||
use clap::{Parser, Subcommand, ValueEnum};
|
use clap::{Parser, Subcommand, ValueEnum};
|
||||||
|
use notify::event::ModifyKind;
|
||||||
use notify::{EventKind, RecommendedWatcher, Watcher};
|
use notify::{EventKind, RecommendedWatcher, Watcher};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -27,6 +28,18 @@ use shadow_rs::shadow;
|
|||||||
|
|
||||||
shadow!(build);
|
shadow!(build);
|
||||||
|
|
||||||
|
/// Local build's 8-byte ASCII short commit hash, suitable for use
|
||||||
|
/// in [`lan_mouse_proto::ProtoEvent::Hello`]. Pads with `'?'` if
|
||||||
|
/// shadow_rs returns an unexpected length so the field is always
|
||||||
|
/// well-formed on the wire.
|
||||||
|
pub fn local_commit() -> [u8; 8] {
|
||||||
|
let bytes = build::SHORT_COMMIT.as_bytes();
|
||||||
|
let mut out = [b'?'; 8];
|
||||||
|
let n = bytes.len().min(8);
|
||||||
|
out[..n].copy_from_slice(&bytes[..n]);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
const CONFIG_FILE_NAME: &str = "config.toml";
|
const CONFIG_FILE_NAME: &str = "config.toml";
|
||||||
const CERT_FILE_NAME: &str = "lan-mouse.pem";
|
const CERT_FILE_NAME: &str = "lan-mouse.pem";
|
||||||
|
|
||||||
@@ -118,13 +131,13 @@ pub enum Command {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
||||||
pub enum CaptureBackend {
|
pub enum CaptureBackend {
|
||||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
#[cfg(libei_capture)]
|
||||||
#[serde(rename = "input-capture-portal")]
|
#[serde(rename = "input-capture-portal")]
|
||||||
InputCapturePortal,
|
InputCapturePortal,
|
||||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
#[cfg(layer_shell_capture)]
|
||||||
#[serde(rename = "layer-shell")]
|
#[serde(rename = "layer-shell")]
|
||||||
LayerShell,
|
LayerShell,
|
||||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
#[cfg(x11_capture)]
|
||||||
#[serde(rename = "x11")]
|
#[serde(rename = "x11")]
|
||||||
X11,
|
X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -140,11 +153,11 @@ pub enum CaptureBackend {
|
|||||||
impl Display for CaptureBackend {
|
impl Display for CaptureBackend {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
#[cfg(libei_capture)]
|
||||||
CaptureBackend::InputCapturePortal => write!(f, "input-capture-portal"),
|
CaptureBackend::InputCapturePortal => write!(f, "input-capture-portal"),
|
||||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
#[cfg(layer_shell_capture)]
|
||||||
CaptureBackend::LayerShell => write!(f, "layer-shell"),
|
CaptureBackend::LayerShell => write!(f, "layer-shell"),
|
||||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
#[cfg(x11_capture)]
|
||||||
CaptureBackend::X11 => write!(f, "X11"),
|
CaptureBackend::X11 => write!(f, "X11"),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
CaptureBackend::Windows => write!(f, "windows"),
|
CaptureBackend::Windows => write!(f, "windows"),
|
||||||
@@ -158,11 +171,11 @@ impl Display for CaptureBackend {
|
|||||||
impl From<CaptureBackend> for input_capture::Backend {
|
impl From<CaptureBackend> for input_capture::Backend {
|
||||||
fn from(backend: CaptureBackend) -> Self {
|
fn from(backend: CaptureBackend) -> Self {
|
||||||
match backend {
|
match backend {
|
||||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
#[cfg(libei_capture)]
|
||||||
CaptureBackend::InputCapturePortal => Self::InputCapturePortal,
|
CaptureBackend::InputCapturePortal => Self::InputCapturePortal,
|
||||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
#[cfg(layer_shell_capture)]
|
||||||
CaptureBackend::LayerShell => Self::LayerShell,
|
CaptureBackend::LayerShell => Self::LayerShell,
|
||||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
#[cfg(x11_capture)]
|
||||||
CaptureBackend::X11 => Self::X11,
|
CaptureBackend::X11 => Self::X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
CaptureBackend::Windows => Self::Windows,
|
CaptureBackend::Windows => Self::Windows,
|
||||||
@@ -175,16 +188,16 @@ impl From<CaptureBackend> for input_capture::Backend {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
||||||
pub enum EmulationBackend {
|
pub enum EmulationBackend {
|
||||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
#[cfg(wlroots_emulation)]
|
||||||
#[serde(rename = "wlroots")]
|
#[serde(rename = "wlroots")]
|
||||||
Wlroots,
|
Wlroots,
|
||||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
#[cfg(libei_emulation)]
|
||||||
#[serde(rename = "libei")]
|
#[serde(rename = "libei")]
|
||||||
Libei,
|
Libei,
|
||||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
#[cfg(rdp_emulation)]
|
||||||
#[serde(rename = "xdp")]
|
#[serde(rename = "xdp")]
|
||||||
Xdp,
|
Xdp,
|
||||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
#[cfg(x11_emulation)]
|
||||||
#[serde(rename = "x11")]
|
#[serde(rename = "x11")]
|
||||||
X11,
|
X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -200,13 +213,13 @@ pub enum EmulationBackend {
|
|||||||
impl From<EmulationBackend> for input_emulation::Backend {
|
impl From<EmulationBackend> for input_emulation::Backend {
|
||||||
fn from(backend: EmulationBackend) -> Self {
|
fn from(backend: EmulationBackend) -> Self {
|
||||||
match backend {
|
match backend {
|
||||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
#[cfg(wlroots_emulation)]
|
||||||
EmulationBackend::Wlroots => Self::Wlroots,
|
EmulationBackend::Wlroots => Self::Wlroots,
|
||||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
#[cfg(libei_emulation)]
|
||||||
EmulationBackend::Libei => Self::Libei,
|
EmulationBackend::Libei => Self::Libei,
|
||||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
#[cfg(rdp_emulation)]
|
||||||
EmulationBackend::Xdp => Self::Xdp,
|
EmulationBackend::Xdp => Self::Xdp,
|
||||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
#[cfg(x11_emulation)]
|
||||||
EmulationBackend::X11 => Self::X11,
|
EmulationBackend::X11 => Self::X11,
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
EmulationBackend::Windows => Self::Windows,
|
EmulationBackend::Windows => Self::Windows,
|
||||||
@@ -220,13 +233,13 @@ impl From<EmulationBackend> for input_emulation::Backend {
|
|||||||
impl Display for EmulationBackend {
|
impl Display for EmulationBackend {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
#[cfg(wlroots_emulation)]
|
||||||
EmulationBackend::Wlroots => write!(f, "wlroots"),
|
EmulationBackend::Wlroots => write!(f, "wlroots"),
|
||||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
#[cfg(libei_emulation)]
|
||||||
EmulationBackend::Libei => write!(f, "libei"),
|
EmulationBackend::Libei => write!(f, "libei"),
|
||||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
#[cfg(rdp_emulation)]
|
||||||
EmulationBackend::Xdp => write!(f, "xdg-desktop-portal"),
|
EmulationBackend::Xdp => write!(f, "xdg-desktop-portal"),
|
||||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
#[cfg(x11_emulation)]
|
||||||
EmulationBackend::X11 => write!(f, "X11"),
|
EmulationBackend::X11 => write!(f, "X11"),
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
EmulationBackend::Windows => write!(f, "windows"),
|
EmulationBackend::Windows => write!(f, "windows"),
|
||||||
@@ -406,7 +419,9 @@ impl Config {
|
|||||||
if event.paths.contains(&self.config_path)
|
if event.paths.contains(&self.config_path)
|
||||||
&& matches!(
|
&& matches!(
|
||||||
event.kind,
|
event.kind,
|
||||||
EventKind::Create(_) | EventKind::Modify(_) | EventKind::Remove(_)
|
EventKind::Create(_)
|
||||||
|
| EventKind::Modify(ModifyKind::Data(_))
|
||||||
|
| EventKind::Remove(_)
|
||||||
)
|
)
|
||||||
&& self.read_from_disk()?
|
&& self.read_from_disk()?
|
||||||
{
|
{
|
||||||
@@ -524,6 +539,11 @@ impl Config {
|
|||||||
}
|
}
|
||||||
Err(e) => log::warn!("{:?} {e}", self.config_path()),
|
Err(e) => log::warn!("{:?} {e}", self.config_path()),
|
||||||
};
|
};
|
||||||
|
if changed {
|
||||||
|
log::info!("config changed");
|
||||||
|
} else {
|
||||||
|
log::info!("config unchanged");
|
||||||
|
}
|
||||||
Ok(changed)
|
Ok(changed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use crate::client::ClientManager;
|
use crate::client::ClientManager;
|
||||||
|
use crate::config::local_commit;
|
||||||
use lan_mouse_ipc::{ClientHandle, DEFAULT_PORT};
|
use lan_mouse_ipc::{ClientHandle, DEFAULT_PORT};
|
||||||
use lan_mouse_proto::{MAX_EVENT_SIZE, ProtoEvent};
|
use lan_mouse_proto::{MAX_EVENT_SIZE, ProtoEvent};
|
||||||
use local_channel::mpsc::{Receiver, Sender, channel};
|
use local_channel::mpsc::{Receiver, Sender, channel};
|
||||||
@@ -197,6 +198,19 @@ async fn connect_to_handle(
|
|||||||
conns.lock().await.insert(addr, conn.clone());
|
conns.lock().await.insert(addr, conn.clone());
|
||||||
connecting.lock().await.remove(&handle);
|
connecting.lock().await.remove(&handle);
|
||||||
|
|
||||||
|
// Best-effort version handshake. Send our commit hash once
|
||||||
|
// immediately after the DTLS handshake; the listen side
|
||||||
|
// mirrors a Hello back so the receive loop can populate
|
||||||
|
// `peer_commit`. Old peers will silently skip this event
|
||||||
|
// per the forward-compat handler in [`receive_loop`].
|
||||||
|
let (buf, len) = ProtoEvent::Hello {
|
||||||
|
commit: local_commit(),
|
||||||
|
}
|
||||||
|
.into();
|
||||||
|
if let Err(e) = conn.send(&buf[..len]).await {
|
||||||
|
log::debug!("hello send to {addr} failed: {e}");
|
||||||
|
}
|
||||||
|
|
||||||
// poll connection for active
|
// poll connection for active
|
||||||
spawn_local(ping_pong(addr, conn.clone(), ping_response.clone()));
|
spawn_local(ping_pong(addr, conn.clone(), ping_response.clone()));
|
||||||
|
|
||||||
@@ -255,16 +269,26 @@ async fn receive_loop(
|
|||||||
) {
|
) {
|
||||||
let mut buf = [0u8; MAX_EVENT_SIZE];
|
let mut buf = [0u8; MAX_EVENT_SIZE];
|
||||||
while conn.recv(&mut buf).await.is_ok() {
|
while conn.recv(&mut buf).await.is_ok() {
|
||||||
if let Ok(event) = buf.try_into() {
|
match buf.try_into() {
|
||||||
log::trace!("{addr} <==<==<== {event}");
|
Ok(event) => {
|
||||||
match event {
|
log::trace!("{addr} <==<==<== {event}");
|
||||||
ProtoEvent::Pong(b) => {
|
match event {
|
||||||
client_manager.set_active_addr(handle, Some(addr));
|
ProtoEvent::Pong(b) => {
|
||||||
client_manager.set_alive(handle, b);
|
client_manager.set_active_addr(handle, Some(addr));
|
||||||
ping_response.borrow_mut().insert(addr);
|
client_manager.set_alive(handle, b);
|
||||||
|
ping_response.borrow_mut().insert(addr);
|
||||||
|
}
|
||||||
|
ProtoEvent::Hello { commit } => {
|
||||||
|
client_manager.set_peer_commit(handle, Some(commit));
|
||||||
|
}
|
||||||
|
event => tx.send((handle, event)).expect("channel closed"),
|
||||||
}
|
}
|
||||||
event => tx.send((handle, event)).expect("channel closed"),
|
|
||||||
}
|
}
|
||||||
|
// Skip undecodable datagrams without dropping the
|
||||||
|
// connection. Each DTLS recv is one framed message, so
|
||||||
|
// skipping is safe and keeps us forward-compatible with
|
||||||
|
// peers that send event types we don't yet know about.
|
||||||
|
Err(e) => log::debug!("ignoring undecodable event from {addr}: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::warn!("recv error");
|
log::warn!("recv error");
|
||||||
@@ -280,6 +304,7 @@ async fn disconnect(
|
|||||||
log::warn!("client ({handle}) @ {addr} connection closed");
|
log::warn!("client ({handle}) @ {addr} connection closed");
|
||||||
conns.lock().await.remove(&addr);
|
conns.lock().await.remove(&addr);
|
||||||
client_manager.set_active_addr(handle, None);
|
client_manager.set_active_addr(handle, None);
|
||||||
|
client_manager.set_peer_commit(handle, None);
|
||||||
let active: Vec<SocketAddr> = conns.lock().await.keys().copied().collect();
|
let active: Vec<SocketAddr> = conns.lock().await.keys().copied().collect();
|
||||||
log::info!("active connections: {active:?}");
|
log::info!("active connections: {active:?}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::config::local_commit;
|
||||||
use crate::listen::{LanMouseListener, ListenEvent, ListenerCreationError};
|
use crate::listen::{LanMouseListener, ListenEvent, ListenerCreationError};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use input_emulation::{EmulationHandle, InputEmulation, InputEmulationError};
|
use input_emulation::{EmulationHandle, InputEmulation, InputEmulationError};
|
||||||
@@ -52,6 +53,17 @@ pub(crate) enum EmulationEvent {
|
|||||||
EmulationEnabled,
|
EmulationEnabled,
|
||||||
/// capture should be released
|
/// capture should be released
|
||||||
ReleaseNotify,
|
ReleaseNotify,
|
||||||
|
/// peer sent us a Hello with its build commit hash. Used to
|
||||||
|
/// populate `client_manager.peer_commit` from the listen side
|
||||||
|
/// too — without this, peer-version visibility silently fails
|
||||||
|
/// whenever the outgoing connection in the *other* direction is
|
||||||
|
/// broken (one-way setups, asymmetric NAT, peer's TCP listener
|
||||||
|
/// down). The connect-side path stays as the primary source;
|
||||||
|
/// this is the defensive fallback.
|
||||||
|
PeerHello {
|
||||||
|
addr: SocketAddr,
|
||||||
|
commit: [u8; 8],
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EmulationRequest {
|
enum EmulationRequest {
|
||||||
@@ -150,6 +162,21 @@ impl ListenTask {
|
|||||||
}
|
}
|
||||||
ProtoEvent::Input(event) => self.emulation_proxy.consume(event, addr),
|
ProtoEvent::Input(event) => self.emulation_proxy.consume(event, addr),
|
||||||
ProtoEvent::Ping => self.listener.reply(addr, ProtoEvent::Pong(self.emulation_proxy.emulation_active.get())).await,
|
ProtoEvent::Ping => self.listener.reply(addr, ProtoEvent::Pong(self.emulation_proxy.emulation_active.get())).await,
|
||||||
|
// Peer's version handshake. Echo our own
|
||||||
|
// commit back so the peer's connect-side
|
||||||
|
// receive_loop populates its `peer_commit`,
|
||||||
|
// AND publish a PeerHello upward so our
|
||||||
|
// service can populate ours from the listen
|
||||||
|
// side too — the connect side is the primary
|
||||||
|
// path, but if the outbound direction is
|
||||||
|
// broken (one-way setup, NAT, peer's TCP
|
||||||
|
// listener down) the version display would
|
||||||
|
// otherwise silently say "unknown" while
|
||||||
|
// the peer is in fact happily talking to us.
|
||||||
|
ProtoEvent::Hello { commit } => {
|
||||||
|
self.listener.reply(addr, ProtoEvent::Hello { commit: local_commit() }).await;
|
||||||
|
self.event_tx.send(EmulationEvent::PeerHello { addr, commit }).expect("channel closed");
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,8 +259,16 @@ async fn read_loop(
|
|||||||
.send(ListenEvent::Msg { event, addr })
|
.send(ListenEvent::Msg { event, addr })
|
||||||
.expect("channel closed"),
|
.expect("channel closed"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("error receiving event: {e}");
|
// Skip the malformed/unknown datagram and keep
|
||||||
break;
|
// listening. Each DTLS recv returns one full
|
||||||
|
// datagram, so a parse error here can't desync a
|
||||||
|
// stream; the next call gets a fresh, framed
|
||||||
|
// message. This makes the protocol forward-
|
||||||
|
// compatible: a peer running a newer Lan Mouse
|
||||||
|
// version can introduce additional event types
|
||||||
|
// and old peers will simply ignore them rather
|
||||||
|
// than dropping the connection.
|
||||||
|
log::debug!("ignoring undecodable event from {addr}: {e}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ fn run() -> Result<(), LanMouseError> {
|
|||||||
#[cfg(feature = "gtk")]
|
#[cfg(feature = "gtk")]
|
||||||
{
|
{
|
||||||
let mut service = start_service()?;
|
let mut service = start_service()?;
|
||||||
let res = lan_mouse_gtk::run();
|
let res = lan_mouse_gtk::run(config::local_commit());
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
// on unix we give the service a chance to terminate gracefully
|
// on unix we give the service a chance to terminate gracefully
|
||||||
|
|||||||
@@ -319,6 +319,17 @@ impl Service {
|
|||||||
EmulationEvent::Connected { addr, fingerprint } => {
|
EmulationEvent::Connected { addr, fingerprint } => {
|
||||||
self.notify_frontend(FrontendEvent::DeviceConnected { addr, fingerprint });
|
self.notify_frontend(FrontendEvent::DeviceConnected { addr, fingerprint });
|
||||||
}
|
}
|
||||||
|
EmulationEvent::PeerHello { addr, commit } => {
|
||||||
|
// Map the peer's source addr back to its client handle
|
||||||
|
// and stamp the commit. Skip if we don't have an
|
||||||
|
// outgoing client configured for this peer (incoming-
|
||||||
|
// only setup) — there's nowhere to display the version
|
||||||
|
// in that case anyway.
|
||||||
|
if let Some(handle) = self.client_manager.get_client(addr) {
|
||||||
|
self.client_manager.set_peer_commit(handle, Some(commit));
|
||||||
|
self.broadcast_client(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user