mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-09-15 17:01:12 +03:00
Compare commits
8 Commits
main-133e1
...
main-00c5e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00c5eee8d8 | ||
|
|
6b1eddef7a | ||
|
|
09889cd839 | ||
|
|
c194df791d | ||
|
|
b316af6a8f | ||
|
|
d09a574380 | ||
|
|
b115208aad | ||
|
|
392af44cbe |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -105,7 +105,7 @@ jobs:
|
||||
# see https://github.com/wingtk/gvsbuild/pull/1004
|
||||
Move-Item "C:\Program Files\Git\usr\bin" "C:\Program Files\Git\usr\notbin"
|
||||
Move-Item "C:\Program Files\Git\bin" "C:\Program Files\Git\notbin"
|
||||
gvsbuild build --msys-dir=C:\msys64 gtk4 libadwaita librsvg
|
||||
gvsbuild build --vs-ver=vs2026 --msys-dir=C:\msys64 gtk4 libadwaita librsvg
|
||||
Move-Item "C:\Program Files\Git\usr\notbin" "C:\Program Files\Git\usr\bin"
|
||||
Move-Item "C:\Program Files\Git\notbin" "C:\Program Files\Git\bin"
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
10
.github/workflows/rust.yml
vendored
10
.github/workflows/rust.yml
vendored
@@ -40,7 +40,6 @@ jobs:
|
||||
- test
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- name: Install Linux deps
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
@@ -49,6 +48,13 @@ jobs:
|
||||
- name: Install macOS dependencies
|
||||
if: runner.os == 'macOS'
|
||||
run: brew install gtk4 libadwaita imagemagick
|
||||
- name: Record macOS native lib versions for cache key
|
||||
if: runner.os == 'macOS'
|
||||
run: |
|
||||
echo "MACOS_LIB_VER=$(brew list --versions glib gtk4 libadwaita | tr '\n' '_')" >> "$GITHUB_ENV"
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
prefix-key: ${{ env.MACOS_LIB_VER }}
|
||||
- name: Install Windows Dependencies - create gtk dir
|
||||
if: runner.os == 'Windows'
|
||||
run: mkdir C:\gtk-build\gtk\x64\release
|
||||
@@ -77,7 +83,7 @@ jobs:
|
||||
py -m venv .venv
|
||||
.venv\Scripts\activate.ps1
|
||||
py -m pip install gvsbuild
|
||||
gvsbuild build --msys-dir=C:\msys64 gtk4 libadwaita librsvg
|
||||
gvsbuild build --vs-ver=vs2026 --msys-dir=C:\msys64 gtk4 libadwaita librsvg
|
||||
- name: cargo build
|
||||
if: matrix.job == 'build'
|
||||
run: cargo build
|
||||
|
||||
14
flake.lock
generated
14
flake.lock
generated
@@ -2,16 +2,16 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1772963539,
|
||||
"narHash": "sha256-9jVDGZnvCckTGdYT53d/EfznygLskyLQXYwJLKMPsZs=",
|
||||
"lastModified": 1788405554,
|
||||
"narHash": "sha256-r2f1oUwixlgq9zOdYLqJLfS/lWBT60/IITjhTKI59JU=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9dcb002ca1690658be4a04645215baea8b95f31d",
|
||||
"rev": "a5cc6f2c37bf518436dc8d1c288ccd0c43c2f4c4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"ref": "nixos-26.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
@@ -29,11 +29,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1773025773,
|
||||
"narHash": "sha256-Wik8+xApNfldpUFjPmJkPdg0RrvUPSWGIZis+A/0N1w=",
|
||||
"lastModified": 1788505699,
|
||||
"narHash": "sha256-PSPDCdbEBEbSDCWcqv5GkbyD2ACQ9Diz6vmEbWdy4dM=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "3c06fdbbd36ff60386a1e590ee0cd52dcd1892bf",
|
||||
"rev": "9eccf73c5b810052f08aa77ae0548c383259f17f",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
24
flake.nix
24
flake.nix
@@ -1,7 +1,8 @@
|
||||
{
|
||||
description = "Nix Flake for lan-mouse";
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
# 26.05 used here to keep allowing builds on x86_64-darwin, bump this to unstable once they deprecate 26.05
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
@@ -30,7 +31,24 @@
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ rust-overlay.overlays.default ];
|
||||
overlays = [
|
||||
rust-overlay.overlays.default
|
||||
|
||||
#NOTE: appstream's meson build injects the literal string
|
||||
# "none required" into linker flags on 'aarch64-darwin', causing clang to fail.
|
||||
# remove this overlay once we bump nixpkgs to unstable branch
|
||||
(
|
||||
final: prev:
|
||||
lib.optionalAttrs prev.stdenv.hostPlatform.isDarwin {
|
||||
appstream = prev.appstream.overrideAttrs (old: {
|
||||
postConfigure = (old.postConfigure or "") + ''
|
||||
substituteInPlace build.ninja \
|
||||
--replace-fail "none required" ""
|
||||
'';
|
||||
});
|
||||
}
|
||||
)
|
||||
];
|
||||
};
|
||||
# Default toolchain for devshell
|
||||
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
||||
@@ -80,7 +98,7 @@
|
||||
libadwaita
|
||||
librsvg
|
||||
]
|
||||
++ lib.optionals pkgs.stdenv.isLinux [
|
||||
++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [
|
||||
libX11
|
||||
libXtst
|
||||
];
|
||||
|
||||
@@ -123,7 +123,6 @@ struct State {
|
||||
focused: Option<Arc<Window>>,
|
||||
global_list: GlobalList,
|
||||
globals: Globals,
|
||||
wayland_fd: RawFd,
|
||||
read_guard: Option<ReadEventsGuard>,
|
||||
qh: QueueHandle<Self>,
|
||||
pending_events: VecDeque<(Position, CaptureEvent)>,
|
||||
@@ -138,7 +137,7 @@ struct Inner {
|
||||
|
||||
impl AsRawFd for Inner {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.state.wayland_fd
|
||||
self.queue.as_fd().as_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +331,6 @@ impl LayerShellInputCapture {
|
||||
active_windows: Vec::new(),
|
||||
focused: None,
|
||||
qh,
|
||||
wayland_fd: queue.as_fd().as_raw_fd(),
|
||||
read_guard: None,
|
||||
pending_events: VecDeque::new(),
|
||||
outputs: vec![],
|
||||
@@ -548,13 +546,12 @@ impl State {
|
||||
}
|
||||
|
||||
impl Inner {
|
||||
fn read(&mut self) -> bool {
|
||||
fn read(&mut self) {
|
||||
match self.state.read_guard.take().unwrap().read() {
|
||||
Ok(_) => true,
|
||||
Err(WaylandError::Io(e)) if e.kind() == ErrorKind::WouldBlock => false,
|
||||
Ok(_) => {}
|
||||
Err(WaylandError::Io(e)) if e.kind() == ErrorKind::WouldBlock => {}
|
||||
Err(WaylandError::Io(e)) => {
|
||||
log::error!("error reading from wayland socket: {e}");
|
||||
false
|
||||
}
|
||||
Err(WaylandError::Protocol(e)) => {
|
||||
panic!("wayland protocol violation: {e}")
|
||||
@@ -564,16 +561,11 @@ impl Inner {
|
||||
|
||||
fn prepare_read(&mut self) -> io::Result<()> {
|
||||
loop {
|
||||
match self.queue.prepare_read() {
|
||||
None => match self.queue.dispatch_pending(&mut self.state) {
|
||||
Ok(_) => continue,
|
||||
Err(DispatchError::Backend(WaylandError::Io(e))) => return Err(e),
|
||||
Err(e) => panic!("failed to dispatch wayland events: {e}"),
|
||||
},
|
||||
Some(r) => {
|
||||
self.state.read_guard = Some(r);
|
||||
break Ok(());
|
||||
}
|
||||
if let Some(guard) = self.queue.prepare_read() {
|
||||
self.state.read_guard = Some(guard);
|
||||
break Ok(());
|
||||
} else {
|
||||
self.dispatch_events();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -655,13 +647,7 @@ impl Stream for LayerShellInputCapture {
|
||||
let inner = guard.get_inner_mut();
|
||||
|
||||
// read events
|
||||
while inner.read() {
|
||||
// prepare next read
|
||||
match inner.prepare_read() {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Poll::Ready(Some(Err(e.into()))),
|
||||
}
|
||||
}
|
||||
inner.read();
|
||||
|
||||
// dispatch the events
|
||||
inner.dispatch_events();
|
||||
|
||||
@@ -18,12 +18,12 @@ use reis::{
|
||||
use std::{
|
||||
cell::Cell,
|
||||
collections::HashMap,
|
||||
io,
|
||||
env, io,
|
||||
num::NonZeroU32,
|
||||
os::unix::net::UnixStream,
|
||||
pin::Pin,
|
||||
rc::Rc,
|
||||
sync::Arc,
|
||||
sync::{Arc, LazyLock},
|
||||
task::{Context, Poll},
|
||||
};
|
||||
use tokio::{
|
||||
@@ -50,6 +50,25 @@ use super::{
|
||||
* prevents receiving further events after a session has been disabled once.
|
||||
* Therefore the session needs to be recreated when the barriers are updated */
|
||||
|
||||
/* mutter also kills the session whenever ei devices come and go, so there the
|
||||
* whole session has to be torn down and recreated on every device change.
|
||||
* Elsewhere that is pure overhead: each restart costs a CreateSession +
|
||||
* ConnectToEIS round trip, and compositors that keep per-session state around
|
||||
* (hyprland leaks a keymap fd per eis session, see hyprwm/Hyprland) can be
|
||||
* driven out of file descriptors by the churn.
|
||||
* Set LM_RESTART_SESSION_ON_DEVICE_CHANGE=1/0 to override the default. */
|
||||
static RESTART_SESSION_ON_DEVICE_CHANGE: LazyLock<bool> =
|
||||
LazyLock::new(restart_session_on_device_change);
|
||||
|
||||
fn restart_session_on_device_change() -> bool {
|
||||
match env::var("LM_RESTART_SESSION_ON_DEVICE_CHANGE").as_deref() {
|
||||
Ok("1") => true,
|
||||
Ok("0") => false,
|
||||
_ => env::var("XDG_CURRENT_DESKTOP")
|
||||
.is_ok_and(|desktops| desktops.to_uppercase().split(':').any(|d| d == "GNOME")),
|
||||
}
|
||||
}
|
||||
|
||||
/// events that necessitate restarting the capture session
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum LibeiNotifyEvent {
|
||||
@@ -555,20 +574,32 @@ async fn handle_ei_event(
|
||||
s.seat.bind_capabilities(all_capabilities);
|
||||
context.flush().map_err(|e| io::Error::new(e.kind(), e))?;
|
||||
}
|
||||
EiEvent::SeatRemoved(_) | /* EiEvent::DeviceAdded(_) | */ EiEvent::DeviceRemoved(_) => {
|
||||
EiEvent::SeatRemoved(_) => {
|
||||
log::debug!("releasing session: {ei_event:?}");
|
||||
release_session.notify_waiters();
|
||||
}
|
||||
/* EiEvent::DeviceAdded(_) | */
|
||||
EiEvent::DeviceRemoved(_) => {
|
||||
if *RESTART_SESSION_ON_DEVICE_CHANGE {
|
||||
log::debug!("releasing session: {ei_event:?}");
|
||||
release_session.notify_waiters();
|
||||
} else {
|
||||
log::debug!("ignoring device change: {ei_event:?}");
|
||||
}
|
||||
}
|
||||
EiEvent::DevicePaused(_) | EiEvent::DeviceResumed(_) => {}
|
||||
EiEvent::DeviceStartEmulating(_) => log::debug!("START EMULATING"),
|
||||
EiEvent::DeviceStopEmulating(_) => log::debug!("STOP EMULATING"),
|
||||
EiEvent::Disconnected(d) => {
|
||||
return Err(CaptureError::Disconnected(format!("{:?}", d.reason)))
|
||||
return Err(CaptureError::Disconnected(format!("{:?}", d.reason)));
|
||||
}
|
||||
_ => {
|
||||
if let Some(pos) = current_client {
|
||||
for event in Event::from_ei_event(ei_event) {
|
||||
event_tx.send((pos, CaptureEvent::Input(event))).await.expect("no channel");
|
||||
event_tx
|
||||
.send((pos, CaptureEvent::Input(event)))
|
||||
.await
|
||||
.expect("no channel");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ rustPlatform.buildRustPackage {
|
||||
libadwaita
|
||||
librsvg
|
||||
]
|
||||
++ lib.optionals stdenv.isLinux [
|
||||
++ lib.optionals stdenv.hostPlatform.isLinux [
|
||||
libX11
|
||||
libXtst
|
||||
];
|
||||
|
||||
@@ -23,12 +23,12 @@ in {
|
||||
};
|
||||
systemd = mkOption {
|
||||
type = types.bool;
|
||||
default = pkgs.stdenv.isLinux;
|
||||
default = pkgs.stdenv.hostPlatform.isLinux;
|
||||
description = "Whether to enable to systemd service for lan-mouse on linux.";
|
||||
};
|
||||
launchd = mkOption {
|
||||
type = types.bool;
|
||||
default = pkgs.stdenv.isDarwin;
|
||||
default = pkgs.stdenv.hostPlatform.isDarwin;
|
||||
description = "Whether to enable to launchd service for lan-mouse on macOS.";
|
||||
};
|
||||
settings = lib.mkOption {
|
||||
|
||||
@@ -518,7 +518,7 @@ impl Config {
|
||||
}
|
||||
|
||||
pub fn read_from_disk(&mut self) -> Result<bool, io::Error> {
|
||||
log::info!("reading config from {:?}", &self.config_path);
|
||||
log::info!("reading config from {:?}", self.config_path);
|
||||
|
||||
let current_config = fs::read_to_string(&self.config_path)?;
|
||||
let current_config = match current_config.parse::<DocumentMut>() {
|
||||
@@ -548,7 +548,7 @@ impl Config {
|
||||
}
|
||||
|
||||
pub fn write_back(&mut self) -> Result<(), io::Error> {
|
||||
log::info!("writing config to {:?}", &self.config_path);
|
||||
log::info!("writing config to {:?}", self.config_path);
|
||||
/* the new config */
|
||||
let new_config = self.config_toml.clone().unwrap_or_default();
|
||||
let new_config = toml_edit::ser::to_string_pretty(&new_config).expect("config");
|
||||
|
||||
Reference in New Issue
Block a user