mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-08 04:20:01 +03:00
Compare commits
1 Commits
v0.10.0
...
fix-wl-obj
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bdca0441c |
1047
Cargo.lock
generated
1047
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
40
Cargo.toml
40
Cargo.toml
@@ -12,7 +12,7 @@ members = [
|
||||
[package]
|
||||
name = "lan-mouse"
|
||||
description = "Software KVM Switch / mouse & keyboard sharing software for Local Area Networks"
|
||||
version = "0.10.0"
|
||||
version = "0.9.1"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
@@ -22,13 +22,13 @@ strip = true
|
||||
lto = "fat"
|
||||
|
||||
[dependencies]
|
||||
input-event = { path = "input-event", version = "0.3.0" }
|
||||
input-emulation = { path = "input-emulation", version = "0.3.0", default-features = false }
|
||||
input-capture = { path = "input-capture", version = "0.3.0", default-features = false }
|
||||
lan-mouse-cli = { path = "lan-mouse-cli", version = "0.2.0" }
|
||||
lan-mouse-gtk = { path = "lan-mouse-gtk", version = "0.2.0", optional = true }
|
||||
lan-mouse-ipc = { path = "lan-mouse-ipc", version = "0.2.0" }
|
||||
lan-mouse-proto = { path = "lan-mouse-proto", version = "0.2.0" }
|
||||
input-event = { path = "input-event", version = "0.2.1" }
|
||||
input-emulation = { path = "input-emulation", version = "0.2.1", default-features = false }
|
||||
input-capture = { path = "input-capture", version = "0.2.0", default-features = false }
|
||||
lan-mouse-cli = { path = "lan-mouse-cli", version = "0.1.0" }
|
||||
lan-mouse-gtk = { path = "lan-mouse-gtk", version = "0.1.0", optional = true }
|
||||
lan-mouse-ipc = { path = "lan-mouse-ipc", version = "0.1.0" }
|
||||
lan-mouse-proto = { path = "lan-mouse-proto", version = "0.1.0" }
|
||||
|
||||
hickory-resolver = "0.24.1"
|
||||
toml = "0.8"
|
||||
@@ -49,7 +49,7 @@ tokio = { version = "1.32.0", features = [
|
||||
futures = "0.3.28"
|
||||
clap = { version = "4.4.11", features = ["derive"] }
|
||||
slab = "0.4.9"
|
||||
thiserror = "2.0.0"
|
||||
thiserror = "1.0.61"
|
||||
tokio-util = "0.7.11"
|
||||
local-channel = "0.1.5"
|
||||
|
||||
@@ -57,21 +57,9 @@ local-channel = "0.1.5"
|
||||
libc = "0.2.148"
|
||||
|
||||
[features]
|
||||
default = [
|
||||
"gtk",
|
||||
"layer_shell_capture",
|
||||
"x11_capture",
|
||||
"libei_capture",
|
||||
"wlroots_emulation",
|
||||
"libei_emulation",
|
||||
"rdp_emulation",
|
||||
"x11_emulation",
|
||||
]
|
||||
default = ["wayland", "x11", "xdg_desktop_portal", "libei", "gtk"]
|
||||
wayland = ["input-capture/wayland", "input-emulation/wayland"]
|
||||
x11 = ["input-capture/x11", "input-emulation/x11"]
|
||||
xdg_desktop_portal = ["input-emulation/xdg_desktop_portal"]
|
||||
libei = ["input-event/libei", "input-capture/libei", "input-emulation/libei"]
|
||||
gtk = ["dep:lan-mouse-gtk"]
|
||||
layer_shell_capture = ["input-capture/layer_shell"]
|
||||
x11_capture = ["input-capture/x11"]
|
||||
libei_capture = ["input-event/libei", "input-capture/libei"]
|
||||
libei_emulation = ["input-event/libei", "input-emulation/libei"]
|
||||
wlroots_emulation = ["input-emulation/wlroots"]
|
||||
x11_emulation = ["input-emulation/x11"]
|
||||
rdp_emulation = ["input-emulation/remote_desktop_portal"]
|
||||
|
||||
333
README.md
333
README.md
@@ -1,65 +1,78 @@
|
||||
# Lan Mouse
|
||||
Lan Mouse is a *cross-platform* mouse and keyboard sharing software similar to universal-control on Apple devices.
|
||||
It allows for using multiple PCs via a single set of mouse and keyboard.
|
||||
Lan Mouse is a mouse and keyboard sharing software similar to universal-control on Apple devices.
|
||||
It allows for using multiple pcs with a single set of mouse and keyboard.
|
||||
This is also known as a Software KVM switch.
|
||||
|
||||
Goal of this project is to be an open-source alternative to proprietary tools like [Synergy 2/3](https://symless.com/synergy), [Share Mouse](https://www.sharemouse.com/de/)
|
||||
and an alternative to other open source tools like [Deskflow](https://github.com/deskflow/deskflow) or [Input Leap](https://github.com/input-leap) (Synergy fork).
|
||||
|
||||
Focus lies on performance, ease of use and a maintainable implementation that can be expanded to support additional backends for e.g. Android, iOS, ... in the future.
|
||||
|
||||
***blazingly fast™*** because it's written in rust.
|
||||
The primary target is Wayland on Linux but Windows and MacOS and Linux on Xorg have partial support as well (see below for more details).
|
||||
|
||||
- _Now with a gtk frontend_
|
||||
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="/screenshots/dark.png?raw=true">
|
||||
<source media="(prefers-color-scheme: light)" srcset="/screenshots/light.png?raw=true">
|
||||
<img alt="Screenshot of Lan-Mouse" srcset="/screenshots/dark.png">
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/feschber/lan-mouse/assets/40996949/016a06a9-76db-4951-9dcc-127d012c59df">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://github.com/feschber/lan-mouse/assets/40996949/d6318340-f811-4e16-9d6e-d1b79883c709">
|
||||
<img alt="Screenshot of Lan-Mouse" srcset="https://github.com/feschber/lan-mouse/assets/40996949/016a06a9-76db-4951-9dcc-127d012c59df">
|
||||
</picture>
|
||||
|
||||
|
||||
Goal of this project is to be an open-source replacement for proprietary tools like [Synergy 2/3](https://symless.com/synergy), [Share Mouse](https://www.sharemouse.com/de/).
|
||||
|
||||
Focus lies on performance and a clean, manageable implementation that can easily be expanded to support additional backends like e.g. Android, iOS, ... .
|
||||
|
||||
***blazingly fast™*** because it's written in rust.
|
||||
|
||||
For an alternative (with slightly different goals) you may check out [Synergy 1 Community Edition](https://github.com/symless/synergy) or [Input Leap](https://github.com/input-leap) (Synergy fork).
|
||||
|
||||
|
||||
> [!WARNING]
|
||||
> DISCLAIMER:
|
||||
> Until [#200](https://github.com/feschber/lan-mouse/pull/200) is merged, all network traffic is **unencrypted** and sent in **plaintext**!
|
||||
> Since this tool has gained a bit of popularity over the past couple of days:
|
||||
>
|
||||
> All network traffic is currently **unencrypted** and sent in **plaintext**.
|
||||
>
|
||||
> A malicious actor with access to the network could read input data or send input events with spoofed IPs to take control over a device.
|
||||
>
|
||||
> Therefore you should only use this tool in your local network with trusted devices.
|
||||
> I take no responsibility for any security breaches!
|
||||
> Therefore you should only use this tool in your local network with trusted devices for now
|
||||
> and I take no responsibility for any leakage of data!
|
||||
|
||||
|
||||
## OS Support
|
||||
|
||||
Most current desktop environments and operating systems are fully supported, this includes
|
||||
- GNOME >= 45
|
||||
- KDE Plasma >= 6.1
|
||||
- Most wlroots based compositors, including Sway (>= 1.8), Hyprland and Wayfire
|
||||
- Windows
|
||||
- MacOS
|
||||
The following table shows support for input emulation (to emulate events received from other clients) and
|
||||
input capture (to send events *to* other clients) on different operating systems:
|
||||
|
||||
|
||||
### Caveats / Known Issues
|
||||
| OS / Desktop Environment | input emulation | input capture |
|
||||
|---------------------------|--------------------------|--------------------------------------|
|
||||
| Wayland (wlroots) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Wayland (KDE) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Wayland (Gnome) | :heavy_check_mark: | :heavy_check_mark: (starting at GNOME 45) |
|
||||
| Windows | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| X11 | :heavy_check_mark: | WIP |
|
||||
| MacOS | :heavy_check_mark: | WIP |
|
||||
|
||||
> [!Important]
|
||||
> - **X11** currently only has support for input emulation, i.e. can only be used on the receiving end.
|
||||
> Gnome -> Sway only partially works (modifier events are not handled correctly)
|
||||
|
||||
> [!Important]
|
||||
> **Wayfire**
|
||||
>
|
||||
> - **Sway / wlroots**: Wlroots based compositors without libei support on the receiving end currently do not handle modifier events on the client side.
|
||||
> This results in CTRL / SHIFT / ALT / SUPER keys not working with a sending device that is NOT using the `layer-shell` backend
|
||||
>
|
||||
> - **Wayfire**: If you are using [Wayfire](https://github.com/WayfireWM/wayfire), make sure to use a recent version (must be newer than October 23rd) and **add `shortcuts-inhibit` to the list of plugins in your wayfire config!**
|
||||
> If you are using [Wayfire](https://github.com/WayfireWM/wayfire), make sure to use a recent version (must be newer than October 23rd) and **add `shortcuts-inhibit` to the list of plugins in your wayfire config!**
|
||||
> Otherwise input capture will not work.
|
||||
>
|
||||
> - **Windows**: The mouse cursor will be invisible when sending input to a Windows system if
|
||||
|
||||
> [!Important]
|
||||
> The mouse cursor will be invisible when sending input to a Windows system if
|
||||
> there is no real mouse connected to the machine.
|
||||
|
||||
For more detailed information about os support see [Detailed OS Support](#detailed-os-support)
|
||||
|
||||
|
||||
## Installation
|
||||
### Install via cargo
|
||||
```sh
|
||||
cargo install lan-mouse
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Arch Linux</summary>
|
||||
### Download from Releases
|
||||
Precompiled release binaries for Windows, MacOS and Linux are available in the [releases section](https://github.com/feschber/lan-mouse/releases).
|
||||
|
||||
For Windows, the depenedencies are included in the .zip file, for other operating systems see [Installing Dependencies](#installing-dependencies).
|
||||
|
||||
### Arch Linux
|
||||
|
||||
Lan Mouse can be installed from the [official repositories](https://archlinux.org/packages/extra/x86_64/lan-mouse/):
|
||||
|
||||
@@ -67,37 +80,46 @@ Lan Mouse can be installed from the [official repositories](https://archlinux.or
|
||||
pacman -S lan-mouse
|
||||
```
|
||||
|
||||
The prerelease version (following `main`) is available on the AUR:
|
||||
It is also available on the AUR:
|
||||
|
||||
```sh
|
||||
# git version (includes latest changes)
|
||||
paru -S lan-mouse-git
|
||||
|
||||
# alternatively
|
||||
paru -S lan-mouse-bin
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
<details>
|
||||
<summary>Nix (OS)</summary>
|
||||
|
||||
### Nix
|
||||
- nixpkgs: [search.nixos.org](https://search.nixos.org/packages?channel=unstable&show=lan-mouse&from=0&size=50&sort=relevance&type=packages&query=lan-mouse)
|
||||
- flake: [README.md](./nix/README.md)
|
||||
</details>
|
||||
|
||||
### Building from source with Nix
|
||||
In the root of the project to build Lan Mouse, run
|
||||
```sh
|
||||
nix-build
|
||||
```
|
||||
|
||||
You can find the executable in `result/bin/lan-mouse` .
|
||||
|
||||
<details>
|
||||
<summary>Manual Installation</summary>
|
||||
### Manual Installation
|
||||
|
||||
First make sure to [install the necessary dependencies](#installing-dependencies).
|
||||
|
||||
Precompiled release binaries for Windows, MacOS and Linux are available in the [releases section](https://github.com/feschber/lan-mouse/releases).
|
||||
For Windows, the depenedencies are included in the .zip file, for other operating systems see [Installing Dependencies](#installing-dependencies).
|
||||
|
||||
Alternatively, the `lan-mouse` binary can be compiled from source (see below).
|
||||
|
||||
### Installing desktop file, app icon and firewall rules (optional)
|
||||
Build in release mode:
|
||||
```sh
|
||||
# install lan-mouse (replace path/to/ with the correct path)
|
||||
sudo cp path/to/lan-mouse /usr/local/bin/
|
||||
cargo build --release
|
||||
```
|
||||
|
||||
Run directly:
|
||||
```sh
|
||||
cargo run --release
|
||||
```
|
||||
|
||||
Install the files:
|
||||
```sh
|
||||
# install lan-mouse
|
||||
sudo cp target/release/lan-mouse /usr/local/bin/
|
||||
|
||||
# install app icon
|
||||
sudo mkdir -p /usr/local/share/icons/hicolor/scalable/apps
|
||||
@@ -115,34 +137,17 @@ sudo cp firewall/lan-mouse.xml /etc/firewalld/services
|
||||
# -> enable the service in firewalld settings
|
||||
```
|
||||
|
||||
Instead of downloading from the releases, the `lan-mouse` binary
|
||||
can be easily compiled via cargo or nix:
|
||||
### Conditional Compilation
|
||||
|
||||
### Compiling and installing manually:
|
||||
```sh
|
||||
# compile in release mode
|
||||
cargo build --release
|
||||
Currently only x11, wayland, windows and MacOS are supported backends.
|
||||
Depending on the toolchain used, support for other platforms is omitted
|
||||
automatically (it does not make sense to build a Windows `.exe` with
|
||||
support for x11 and wayland backends).
|
||||
|
||||
# install lan-mouse
|
||||
sudo cp target/release/lan-mouse /usr/local/bin/
|
||||
```
|
||||
However one might still want to omit support for e.g. wayland, x11 or libei on
|
||||
a Linux system.
|
||||
|
||||
### Compiling and installing via cargo:
|
||||
```sh
|
||||
# will end up in ~/.cargo/bin
|
||||
cargo install lan-mouse
|
||||
```
|
||||
|
||||
### Compiling and installing via nix:
|
||||
```sh
|
||||
# you can find the executable in result/bin/lan-mouse
|
||||
nix-build
|
||||
```
|
||||
### Conditional compilation
|
||||
Support for other platforms is omitted automatically based on the active
|
||||
rust toolchain.
|
||||
|
||||
Additionally, available backends and frontends can be configured manually via
|
||||
This is possible through
|
||||
[cargo features](https://doc.rust-lang.org/cargo/reference/features.html).
|
||||
|
||||
E.g. if only wayland support is needed, the following command produces
|
||||
@@ -151,17 +156,14 @@ an executable with just support for wayland:
|
||||
cargo build --no-default-features --features wayland
|
||||
```
|
||||
For a detailed list of available features, checkout the [Cargo.toml](./Cargo.toml)
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
|
||||
## Installing Dependencies for Development / Compiling from Source
|
||||
## Installing Dependencies
|
||||
<details>
|
||||
<summary>MacOS</summary>
|
||||
|
||||
```sh
|
||||
brew install libadwaita pkg-config
|
||||
brew install libadwaita
|
||||
```
|
||||
</details>
|
||||
|
||||
@@ -188,24 +190,12 @@ sudo pacman -S libadwaita gtk libx11 libxtst
|
||||
sudo dnf install libadwaita-devel libXtst-devel libX11-devel
|
||||
```
|
||||
</details>
|
||||
<details>
|
||||
<summary>Nix</summary>
|
||||
|
||||
```sh
|
||||
nix-shell .
|
||||
```
|
||||
</details>
|
||||
<details>
|
||||
<summary>Nix (flake)</summary>
|
||||
|
||||
```sh
|
||||
nix develop
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Windows</summary>
|
||||
|
||||
> [!NOTE]
|
||||
> This is only necessary when building lan-mouse from source. The windows release comes with precompiled gtk dlls.
|
||||
|
||||
- First install [Rust](https://www.rust-lang.org/tools/install).
|
||||
|
||||
- Then follow the instructions at [gtk-rs.org](https://gtk-rs.org/gtk4-rs/stable/latest/book/installation_windows.html)
|
||||
@@ -236,20 +226,18 @@ python -m pipx ensurepath
|
||||
pipx install gvsbuild
|
||||
|
||||
# build gtk + libadwaita
|
||||
gvsbuild build gtk4 libadwaita librsvg adwaita-icon-theme
|
||||
gvsbuild build gtk4 libadwaita librsvg
|
||||
```
|
||||
|
||||
- **Make sure to add the directory** `C:\gtk-build\gtk\x64\release\bin`
|
||||
[**to the `PATH` environment variable**]((https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14))). Otherwise the project will fail to build.
|
||||
|
||||
To avoid building GTK from source, it is possible to disable
|
||||
the gtk frontend (see conditional compilation).
|
||||
the gtk frontend (see conditional compilation below).
|
||||
</details>
|
||||
|
||||
## Usage
|
||||
<details>
|
||||
<summary>Gtk Frontend</summary>
|
||||
|
||||
### Gtk Frontend
|
||||
By default the gtk frontend will open when running `lan-mouse`.
|
||||
|
||||
To add a new connection, simply click the `Add` button on *both* devices,
|
||||
@@ -257,11 +245,8 @@ enter the corresponding hostname and activate it.
|
||||
|
||||
If the mouse can not be moved onto a device, make sure you have port `4242` (or the one selected)
|
||||
opened up in your firewall.
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Command Line Interface</summary>
|
||||
|
||||
### Command Line Interface
|
||||
The cli interface can be enabled using `--frontend cli` as commandline arguments.
|
||||
Type `help` to list the available commands.
|
||||
|
||||
@@ -275,17 +260,13 @@ $ cargo run --release -- --frontend cli
|
||||
(...)
|
||||
> activate 0
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Daemon Mode</summary>
|
||||
|
||||
Lan Mouse can be launched in daemon mode to keep it running in the background (e.g. for use in a systemd-service).
|
||||
|
||||
### Daemon
|
||||
Lan Mouse can be launched in daemon mode to keep it running in the background.
|
||||
To do so, add `--daemon` to the commandline args:
|
||||
|
||||
```sh
|
||||
lan-mouse --daemon
|
||||
$ cargo run --release -- --daemon
|
||||
```
|
||||
|
||||
In order to start lan-mouse with a graphical session automatically,
|
||||
@@ -298,7 +279,6 @@ cp service/lan-mouse.service ~/.config/systemd/user
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now lan-mouse.service
|
||||
```
|
||||
</details>
|
||||
|
||||
## Configuration
|
||||
To automatically load clients on startup, the file `$XDG_CONFIG_HOME/lan-mouse/config.toml` is parsed.
|
||||
@@ -354,60 +334,109 @@ Where `left` can be either `left`, `right`, `top` or `bottom`.
|
||||
- [x] Liveness tracking: Automatically release keys, when server offline
|
||||
- [x] MacOS KeyCode Translation
|
||||
- [x] Libei Input Capture
|
||||
- [x] MacOS Input Capture
|
||||
- [x] Windows Input Capture
|
||||
- [ ] *Encryption* (WIP)
|
||||
- [ ] X11 Input Capture
|
||||
- [ ] Windows Input Capture
|
||||
- [ ] MacOS Input Capture
|
||||
- [ ] Latency measurement and visualization
|
||||
- [ ] Bandwidth usage measurement and visualization
|
||||
- [ ] Clipboard support
|
||||
- [ ] *Encryption*
|
||||
|
||||
## Protocol
|
||||
Currently *all* mouse and keyboard events are sent via **UDP** for performance reasons.
|
||||
Each event is sent as one single datagram, currently without any acknowledgement to guarantee 0% packet loss.
|
||||
This means, any packet that is lost results in a discarded mouse / key event, which is ignored for now.
|
||||
|
||||
**UDP** also has the additional benefit that no reconnection logic is required.
|
||||
Any client can just go offline and it will simply start working again as soon as it comes back online.
|
||||
|
||||
Additionally a tcp server is hosted for data that needs to be sent reliably (e.g. the keymap from the server or clipboard contents in the future) can be requested via a tcp connection.
|
||||
|
||||
## Bandwidth considerations
|
||||
The most bandwidth is taken up by mouse events. A typical office mouse has a polling rate of 125Hz
|
||||
while gaming mice typically have a much higher polling rate of 1000Hz.
|
||||
A mouse Event consists of 21 Bytes:
|
||||
- 1 Byte for the event type enum,
|
||||
- 4 Bytes (u32) for the timestamp,
|
||||
- 8 Bytes (f64) for dx,
|
||||
- 8 Bytes (f64) for dy.
|
||||
|
||||
Additionally the IP header with 20 Bytes and the udp header with 8 Bytes take up another 28 Byte.
|
||||
So in total there is 49 * 1000 Bytes/s for a 1000Hz gaming mouse.
|
||||
This makes for a bandwidth requirement of 392 kbit/s in total _even_ for a high end gaming mouse.
|
||||
So bandwidth is a non-issue.
|
||||
|
||||
Larger data chunks, like the keymap are offered by the server via tcp listening on the same port.
|
||||
This way we dont need to implement any congestion control and leave this up to tcp.
|
||||
In the future this can be used for e.g. clipboard contents as well.
|
||||
|
||||
## Packets per Second
|
||||
While on LAN the performance is great,
|
||||
some WIFI cards seem to struggle with the amount of packets per second,
|
||||
particularly on high-end gaming mice with 1000Hz+ polling rates.
|
||||
|
||||
The plan is to implement a way of accumulating packets and sending them as
|
||||
one single key event to reduce the packet rate (basically reducing the polling
|
||||
rate artificially).
|
||||
|
||||
The way movement data is currently sent is also quite wasteful since even a 16bit integer
|
||||
is likely enough to represent even the fastest possible mouse movement.
|
||||
A different encoding that is more efficient for smaller values like
|
||||
[Protocol Buffers](https://protobuf.dev/programming-guides/encoding/)
|
||||
would be a better choice for the future and could also help for WIFI connections.
|
||||
|
||||
## Security
|
||||
Sending key and mouse event data over the local network might not be the biggest security concern but in any public network or business environment it's *QUITE* a problem to basically broadcast your keystrokes.
|
||||
- There should be an encryption layer below the application to enable a secure link.
|
||||
- The encryption keys could be generated by the graphical frontend.
|
||||
|
||||
|
||||
## Detailed OS Support
|
||||
## Wayland support
|
||||
### Input Emulation (for receiving events)
|
||||
On wayland input-emulation is in an early/unstable state as of writing this.
|
||||
|
||||
In order to use a device for sending events, an **input-capture** backend is required, while receiving events requires
|
||||
a supported **input-emulation** *and* **input-capture** backend.
|
||||
For this reason a suitable backend is chosen based on the active desktop environment / compositor.
|
||||
|
||||
A suitable backend is chosen automatically based on the active desktop environment / compositor.
|
||||
Different compositors have different ways of enabling input emulation:
|
||||
|
||||
The following sections detail the emulation and capture backends provided by lan-mouse and their support in desktop environments / operating systems.
|
||||
#### Wlroots
|
||||
Most wlroots-based compositors like Hyprland and Sway support the following
|
||||
unstable wayland protocols for keyboard and mouse emulation:
|
||||
- [virtual-keyboard-unstable-v1](https://wayland.app/protocols/virtual-keyboard-unstable-v1)
|
||||
- [wlr-virtual-pointer-unstable-v1](https://wayland.app/protocols/wlr-virtual-pointer-unstable-v1)
|
||||
|
||||
### Input Emulation Support
|
||||
#### KDE
|
||||
KDE also has a protocol for input emulation ([kde-fake-input](https://wayland.app/protocols/kde-fake-input)),
|
||||
it is however not exposed to third party applications.
|
||||
|
||||
| Desktop / Backend | layer-shell | libei | windows | macos | x11 |
|
||||
|---------------------------|--------------------------|--------------------------|--------------------------|----------------------------------------|-----|
|
||||
| Wayland (wlroots) | :heavy_check_mark: | | | | |
|
||||
| Wayland (KDE) | :heavy_check_mark: | :heavy_check_mark: | | | |
|
||||
| Wayland (Gnome) | | :heavy_check_mark: | | | |
|
||||
| Windows | | | :heavy_check_mark: | | |
|
||||
| MacOS | | | | :heavy_check_mark: | |
|
||||
| X11 | | | | | WIP |
|
||||
The recommended way to emulate input on KDE is the
|
||||
[freedesktop remote-desktop-portal](https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.RemoteDesktop).
|
||||
|
||||
- `wlroots`: This backend makes use of the [wlr-virtual-pointer-unstable-v1](https://wayland.app/protocols/wlr-virtual-pointer-unstable-v1) and [virtual-keyboard-unstable-v1](https://wayland.app/protocols/virtual-keyboard-unstable-v1) protocols and is supported by most wlroots based compositors.
|
||||
- `libei`: This backend uses [libei](https://gitlab.freedesktop.org/libinput/libei) and is supported by GNOME >= 45 or KDE Plasma >= 6.1.
|
||||
- `xdp`: This backend uses the [freedesktop remote-desktop-portal](https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.RemoteDesktop) and is supported on GNOME and Plasma.
|
||||
- `x11`: Backend for X11 sessions.
|
||||
- `windows`: Backend for Windows.
|
||||
- `macos`: Backend for MacOS.
|
||||
#### Gnome
|
||||
Gnome uses [libei](https://gitlab.freedesktop.org/libinput/libei) for input emulation and capture,
|
||||
which has the goal to become the general approach for emulating and capturing Input on Wayland.
|
||||
|
||||
### Input capture
|
||||
|
||||
To capture mouse and keyboard input, a few things are necessary:
|
||||
- Displaying an immovable surface at screen edges
|
||||
- Locking the mouse in place
|
||||
- (optionally but highly recommended) reading unaccelerated mouse input
|
||||
|
||||
### Input Capture Support
|
||||
| Required Protocols (Event Emitting) | Sway | Kwin | Gnome |
|
||||
|----------------------------------------|--------------------|----------------------|----------------------|
|
||||
| pointer-constraints-unstable-v1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| relative-pointer-unstable-v1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| keyboard-shortcuts-inhibit-unstable-v1 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| wlr-layer-shell-unstable-v1 | :heavy_check_mark: | :heavy_check_mark: | :x: |
|
||||
|
||||
| Desktop / Backend | wlroots | libei | remote-desktop portal | windows | macos | x11 |
|
||||
|---------------------------|--------------------------|--------------------------|--------------------------|--------------------------|----------------------------------------|--------------------|
|
||||
| Wayland (wlroots) | :heavy_check_mark: | | | | | |
|
||||
| Wayland (KDE) | | :heavy_check_mark: | :heavy_check_mark: | | | |
|
||||
| Wayland (Gnome) | | :heavy_check_mark: | :heavy_check_mark: | | | |
|
||||
| Windows | | | | :heavy_check_mark: | | |
|
||||
| MacOS | | | | | :heavy_check_mark: | |
|
||||
| X11 | | | | | | :heavy_check_mark: |
|
||||
|
||||
- `layer-shell`: This backend creates a single pixel wide window on the edges of Displays to capture the cursor using the [layer-shell protocol](https://wayland.app/protocols/wlr-layer-shell-unstable-v1).
|
||||
- `libei`: This backend uses [libei](https://gitlab.freedesktop.org/libinput/libei) and is supported by GNOME >= 45 or KDE Plasma >= 6.1.
|
||||
- `windows`: Backend for input capture on Windows.
|
||||
- `macos`: Backend for input capture on MacOS.
|
||||
- `x11`: TODO (not yet supported)
|
||||
The [zwlr\_virtual\_pointer\_manager\_v1](wlr-virtual-pointer-unstable-v1) is required
|
||||
to display surfaces on screen edges and used to display the immovable window on
|
||||
both wlroots based compositors and KDE.
|
||||
|
||||
Gnome unfortunately does not support this protocol
|
||||
and [likely won't ever support it](https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/1141).
|
||||
|
||||
~In order for layershell surfaces to be able to lock the pointer using the pointer\_constraints protocol [this patch](https://github.com/swaywm/sway/pull/7178) needs to be applied to sway.~
|
||||
(this works natively on sway versions >= 1.8)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "input-capture"
|
||||
description = "cross-platform input-capture library used by lan-mouse"
|
||||
version = "0.3.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
@@ -10,10 +10,10 @@ repository = "https://github.com/feschber/lan-mouse"
|
||||
futures = "0.3.28"
|
||||
futures-core = "0.3.30"
|
||||
log = "0.4.22"
|
||||
input-event = { path = "../input-event", version = "0.3.0" }
|
||||
input-event = { path = "../input-event", version = "0.2.1" }
|
||||
memmap = "0.7"
|
||||
tempfile = "3.8"
|
||||
thiserror = "2.0.0"
|
||||
thiserror = "1.0.61"
|
||||
tokio = { version = "1.32.0", features = [
|
||||
"io-util",
|
||||
"io-std",
|
||||
@@ -40,18 +40,18 @@ wayland-protocols-wlr = { version = "0.3.1", features = [
|
||||
"client",
|
||||
], optional = true }
|
||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||
ashpd = { version = "0.10", default-features = false, features = [
|
||||
ashpd = { version = "0.9", default-features = false, features = [
|
||||
"tokio",
|
||||
], optional = true }
|
||||
reis = { version = "0.4", features = ["tokio"], optional = true }
|
||||
reis = { version = "0.2", features = ["tokio"], optional = true }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
core-graphics = { version = "0.24.0", features = ["highsierra"] }
|
||||
core-foundation = "0.10.0"
|
||||
core-graphics = { version = "0.23", features = ["highsierra"] }
|
||||
core-foundation = "0.9.4"
|
||||
core-foundation-sys = "0.8.6"
|
||||
libc = "0.2.155"
|
||||
keycode = "0.4.0"
|
||||
bitflags = "2.6.0"
|
||||
bitflags = "2.5.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows = { version = "0.58.0", features = [
|
||||
@@ -65,8 +65,8 @@ windows = { version = "0.58.0", features = [
|
||||
] }
|
||||
|
||||
[features]
|
||||
default = ["layer_shell", "x11", "libei"]
|
||||
layer_shell = [
|
||||
default = ["wayland", "x11", "libei"]
|
||||
wayland = [
|
||||
"dep:wayland-client",
|
||||
"dep:wayland-protocols",
|
||||
"dep:wayland-protocols-wlr",
|
||||
|
||||
@@ -8,9 +8,9 @@ pub enum InputCaptureError {
|
||||
Capture(#[from] CaptureError),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
use std::io;
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
use wayland_client::{
|
||||
backend::WaylandError,
|
||||
globals::{BindError, GlobalError},
|
||||
@@ -19,10 +19,26 @@ use wayland_client::{
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use ashpd::desktop::ResponseError;
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use reis::tokio::{EiConvertEventStreamError, HandshakeError};
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
use core_graphics::base::CGError;
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("error in libei stream: {inner:?}")]
|
||||
pub struct ReisConvertEventStreamError {
|
||||
inner: EiConvertEventStreamError,
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
impl From<EiConvertEventStreamError> for ReisConvertEventStreamError {
|
||||
fn from(e: EiConvertEventStreamError) -> Self {
|
||||
Self { inner: e }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CaptureError {
|
||||
#[error("activation stream closed unexpectedly")]
|
||||
@@ -32,8 +48,11 @@ pub enum CaptureError {
|
||||
#[error("io error: `{0}`")]
|
||||
Io(#[from] std::io::Error),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("libei error: `{0}`")]
|
||||
Reis(#[from] reis::Error),
|
||||
#[error("error in libei stream: `{0}`")]
|
||||
Reis(#[from] ReisConvertEventStreamError),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("libei handshake failed: `{0}`")]
|
||||
Handshake(#[from] HandshakeError),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error(transparent)]
|
||||
Portal(#[from] ashpd::Error),
|
||||
@@ -64,7 +83,7 @@ pub enum CaptureCreationError {
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("error creating input-capture-portal backend: `{0}`")]
|
||||
Libei(#[from] LibeiCaptureCreationError),
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[error("error creating layer-shell capture backend: `{0}`")]
|
||||
LayerShell(#[from] LayerShellCaptureCreationError),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
@@ -102,7 +121,7 @@ pub enum LibeiCaptureCreationError {
|
||||
Ashpd(#[from] ashpd::Error),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("{protocol} protocol not supported: {inner}")]
|
||||
pub struct WaylandBindError {
|
||||
@@ -110,14 +129,14 @@ pub struct WaylandBindError {
|
||||
protocol: &'static str,
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
impl WaylandBindError {
|
||||
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
||||
Self { inner, protocol }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum LayerShellCaptureCreationError {
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -21,8 +21,8 @@ mod libei;
|
||||
#[cfg(target_os = "macos")]
|
||||
mod macos;
|
||||
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
mod layer_shell;
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
mod wayland;
|
||||
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
@@ -87,7 +87,7 @@ impl Display for Position {
|
||||
pub enum Backend {
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
InputCapturePortal,
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
LayerShell,
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
X11,
|
||||
@@ -103,7 +103,7 @@ impl Display for Backend {
|
||||
match self {
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::InputCapturePortal => write!(f, "input-capture-portal"),
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::LayerShell => write!(f, "layer-shell"),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11 => write!(f, "X11"),
|
||||
@@ -132,35 +132,31 @@ pub struct InputCapture {
|
||||
impl InputCapture {
|
||||
/// create a new client with the given id
|
||||
pub async fn create(&mut self, id: CaptureHandle, pos: Position) -> Result<(), CaptureError> {
|
||||
assert!(!self.id_map.contains_key(&id));
|
||||
|
||||
self.id_map.insert(id, pos);
|
||||
|
||||
if let Some(v) = self.position_map.get_mut(&pos) {
|
||||
v.push(id);
|
||||
Ok(())
|
||||
} else {
|
||||
self.position_map.insert(pos, vec![id]);
|
||||
self.id_map.insert(id, pos);
|
||||
self.capture.create(pos).await
|
||||
}
|
||||
}
|
||||
|
||||
/// destroy the client with the given id, if it exists
|
||||
pub async fn destroy(&mut self, id: CaptureHandle) -> Result<(), CaptureError> {
|
||||
let pos = self
|
||||
.id_map
|
||||
.remove(&id)
|
||||
.expect("no position for this handle");
|
||||
|
||||
log::debug!("destroying capture {id} @ {pos}");
|
||||
let remaining = self.position_map.get_mut(&pos).expect("id vector");
|
||||
remaining.retain(|&i| i != id);
|
||||
|
||||
log::debug!("remaining ids @ {pos}: {remaining:?}");
|
||||
if remaining.is_empty() {
|
||||
log::debug!("destroying capture @ {pos} - no remaining ids");
|
||||
self.position_map.remove(&pos);
|
||||
self.capture.destroy(pos).await?;
|
||||
if let Some(pos) = self.id_map.remove(&id) {
|
||||
let destroy = if let Some(v) = self.position_map.get_mut(&pos) {
|
||||
v.retain(|&i| i != id);
|
||||
// we were the last id registered at this position
|
||||
v.is_empty()
|
||||
} else {
|
||||
// nothing to destroy
|
||||
false
|
||||
};
|
||||
if destroy {
|
||||
self.position_map.remove(&pos);
|
||||
self.capture.destroy(pos).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -287,8 +283,8 @@ async fn create_backend(
|
||||
match backend {
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::InputCapturePortal => Ok(Box::new(libei::LibeiInputCapture::new().await?)),
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
Backend::LayerShell => Ok(Box::new(layer_shell::LayerShellInputCapture::new()?)),
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::LayerShell => Ok(Box::new(wayland::LayerShellInputCapture::new()?)),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11 => Ok(Box::new(x11::X11InputCapture::new()?)),
|
||||
#[cfg(windows)]
|
||||
@@ -316,7 +312,7 @@ async fn create(
|
||||
for backend in [
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::InputCapturePortal,
|
||||
#[cfg(all(unix, feature = "layer_shell", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::LayerShell,
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11,
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use ashpd::{
|
||||
desktop::{
|
||||
input_capture::{
|
||||
Activated, ActivatedBarrier, Barrier, BarrierID, Capabilities, InputCapture, Region,
|
||||
Zones,
|
||||
},
|
||||
input_capture::{Activated, Barrier, BarrierID, Capabilities, InputCapture, Region, Zones},
|
||||
Session,
|
||||
},
|
||||
enumflags2::BitFlags,
|
||||
@@ -11,15 +8,14 @@ use ashpd::{
|
||||
use async_trait::async_trait;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use reis::{
|
||||
ei::{self, handshake::ContextType},
|
||||
event::{Connection, DeviceCapability, EiEvent},
|
||||
tokio::EiConvertEventStream,
|
||||
ei,
|
||||
event::{DeviceCapability, EiEvent},
|
||||
tokio::{EiConvertEventStream, EiEventStream},
|
||||
};
|
||||
use std::{
|
||||
cell::Cell,
|
||||
collections::HashMap,
|
||||
io,
|
||||
num::NonZeroU32,
|
||||
os::unix::net::UnixStream,
|
||||
pin::Pin,
|
||||
rc::Rc,
|
||||
@@ -36,13 +32,14 @@ use tokio::{
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use futures_core::Stream;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use input_event::Event;
|
||||
|
||||
use crate::CaptureEvent;
|
||||
|
||||
use super::{
|
||||
error::{CaptureError, LibeiCaptureCreationError},
|
||||
error::{CaptureError, LibeiCaptureCreationError, ReisConvertEventStreamError},
|
||||
Capture as LanMouseInputCapture, Position,
|
||||
};
|
||||
|
||||
@@ -68,6 +65,22 @@ pub struct LibeiInputCapture<'a> {
|
||||
terminated: bool,
|
||||
}
|
||||
|
||||
static INTERFACES: Lazy<HashMap<&'static str, u32>> = Lazy::new(|| {
|
||||
let mut m = HashMap::new();
|
||||
m.insert("ei_connection", 1);
|
||||
m.insert("ei_callback", 1);
|
||||
m.insert("ei_pingpong", 1);
|
||||
m.insert("ei_seat", 1);
|
||||
m.insert("ei_device", 2);
|
||||
m.insert("ei_pointer", 1);
|
||||
m.insert("ei_pointer_absolute", 1);
|
||||
m.insert("ei_scroll", 1);
|
||||
m.insert("ei_button", 1);
|
||||
m.insert("ei_keyboard", 1);
|
||||
m.insert("ei_touchscreen", 1);
|
||||
m
|
||||
});
|
||||
|
||||
/// returns (start pos, end pos), inclusive
|
||||
fn pos_to_barrier(r: &Region, pos: Position) -> (i32, i32, i32, i32) {
|
||||
let (x, y) = (r.x_offset(), r.y_offset());
|
||||
@@ -105,7 +118,7 @@ impl From<ICBarrier> for Barrier {
|
||||
fn select_barriers(
|
||||
zones: &Zones,
|
||||
clients: &[Position],
|
||||
next_barrier_id: &mut NonZeroU32,
|
||||
next_barrier_id: &mut u32,
|
||||
) -> (Vec<ICBarrier>, HashMap<BarrierID, Position>) {
|
||||
let mut pos_for_barrier = HashMap::new();
|
||||
let mut barriers: Vec<ICBarrier> = vec![];
|
||||
@@ -116,9 +129,7 @@ fn select_barriers(
|
||||
.iter()
|
||||
.map(|r| {
|
||||
let id = *next_barrier_id;
|
||||
*next_barrier_id = next_barrier_id
|
||||
.checked_add(1)
|
||||
.expect("barrier id out of range");
|
||||
*next_barrier_id = id + 1;
|
||||
let position = pos_to_barrier(r, *pos);
|
||||
pos_for_barrier.insert(id, *pos);
|
||||
ICBarrier::new(id, position)
|
||||
@@ -133,7 +144,7 @@ async fn update_barriers(
|
||||
input_capture: &InputCapture<'_>,
|
||||
session: &Session<'_, InputCapture<'_>>,
|
||||
active_clients: &[Position],
|
||||
next_barrier_id: &mut NonZeroU32,
|
||||
next_barrier_id: &mut u32,
|
||||
) -> Result<(Vec<ICBarrier>, HashMap<BarrierID, Position>), ashpd::Error> {
|
||||
let zones = input_capture.zones(session).await?.response()?;
|
||||
log::debug!("zones: {zones:?}");
|
||||
@@ -157,7 +168,7 @@ async fn create_session<'a>(
|
||||
log::debug!("creating input capture session");
|
||||
input_capture
|
||||
.create_session(
|
||||
None,
|
||||
&ashpd::WindowIdentifier::default(),
|
||||
Capabilities::Keyboard | Capabilities::Pointer | Capabilities::Touchscreen,
|
||||
)
|
||||
.await
|
||||
@@ -166,7 +177,7 @@ async fn create_session<'a>(
|
||||
async fn connect_to_eis(
|
||||
input_capture: &InputCapture<'_>,
|
||||
session: &Session<'_, InputCapture<'_>>,
|
||||
) -> Result<(ei::Context, Connection, EiConvertEventStream), CaptureError> {
|
||||
) -> Result<(ei::Context, EiConvertEventStream), CaptureError> {
|
||||
log::debug!("connect_to_eis");
|
||||
let fd = input_capture.connect_to_eis(session).await?;
|
||||
|
||||
@@ -176,11 +187,17 @@ async fn connect_to_eis(
|
||||
|
||||
// create ei context
|
||||
let context = ei::Context::new(stream)?;
|
||||
let (conn, event_stream) = context
|
||||
.handshake_tokio("de.feschber.LanMouse", ContextType::Receiver)
|
||||
.await?;
|
||||
let mut event_stream = EiEventStream::new(context.clone())?;
|
||||
let response = reis::tokio::ei_handshake(
|
||||
&mut event_stream,
|
||||
"de.feschber.LanMouse",
|
||||
ei::handshake::ContextType::Receiver,
|
||||
&INTERFACES,
|
||||
)
|
||||
.await?;
|
||||
let event_stream = EiConvertEventStream::new(event_stream, response.serial);
|
||||
|
||||
Ok((context, conn, event_stream))
|
||||
Ok((context, event_stream))
|
||||
}
|
||||
|
||||
async fn libei_event_handler(
|
||||
@@ -194,7 +211,8 @@ async fn libei_event_handler(
|
||||
let ei_event = ei_event_stream
|
||||
.next()
|
||||
.await
|
||||
.ok_or(CaptureError::EndOfStream)??;
|
||||
.ok_or(CaptureError::EndOfStream)?
|
||||
.map_err(ReisConvertEventStreamError::from)?;
|
||||
log::trace!("from ei: {ei_event:?}");
|
||||
let client = current_pos.get();
|
||||
handle_ei_event(ei_event, client, &context, &event_tx, &release_session).await?;
|
||||
@@ -250,7 +268,7 @@ async fn do_capture(
|
||||
/* safety: libei_task does not outlive Self */
|
||||
let input_capture = unsafe { &*input_capture };
|
||||
let mut active_clients: Vec<Position> = vec![];
|
||||
let mut next_barrier_id = NonZeroU32::new(1).expect("id must be non-zero");
|
||||
let mut next_barrier_id = 1u32;
|
||||
|
||||
let mut zones_changed = input_capture.receive_zones_changed().await?;
|
||||
|
||||
@@ -340,7 +358,7 @@ async fn do_capture_session(
|
||||
session: &mut Session<'_, InputCapture<'_>>,
|
||||
event_tx: &Sender<(Position, CaptureEvent)>,
|
||||
active_clients: &[Position],
|
||||
next_barrier_id: &mut NonZeroU32,
|
||||
next_barrier_id: &mut u32,
|
||||
notify_release: &Notify,
|
||||
cancel: (CancellationToken, CancellationToken),
|
||||
) -> Result<(), CaptureError> {
|
||||
@@ -349,7 +367,7 @@ async fn do_capture_session(
|
||||
let current_pos = Rc::new(Cell::new(None));
|
||||
|
||||
// connect to eis server
|
||||
let (context, _conn, ei_event_stream) = connect_to_eis(input_capture, session).await?;
|
||||
let (context, ei_event_stream) = connect_to_eis(input_capture, session).await?;
|
||||
|
||||
// set barriers
|
||||
let (barriers, pos_for_barrier_id) =
|
||||
@@ -397,9 +415,9 @@ async fn do_capture_session(
|
||||
|
||||
// get barrier id from activation
|
||||
let barrier_id = match activated.barrier_id() {
|
||||
Some(ActivatedBarrier::Barrier(id)) => id,
|
||||
Some(bid) => bid,
|
||||
// workaround for KDE plasma not reporting barrier ids
|
||||
Some(ActivatedBarrier::UnknownBarrier) | None => find_corresponding_client(&barriers, activated.cursor_position().expect("no cursor position reported by compositor")),
|
||||
None => find_corresponding_client(&barriers, activated.cursor_position().expect("no cursor position reported by compositor")),
|
||||
};
|
||||
|
||||
// find client corresponding to barrier
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "input-emulation"
|
||||
description = "cross-platform input emulation library used by lan-mouse"
|
||||
version = "0.3.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
@@ -10,8 +10,8 @@ repository = "https://github.com/feschber/lan-mouse"
|
||||
async-trait = "0.1.80"
|
||||
futures = "0.3.28"
|
||||
log = "0.4.22"
|
||||
input-event = { path = "../input-event", version = "0.3.0" }
|
||||
thiserror = "2.0.0"
|
||||
input-event = { path = "../input-event", version = "0.2.1" }
|
||||
thiserror = "1.0.61"
|
||||
tokio = { version = "1.32.0", features = [
|
||||
"io-util",
|
||||
"io-std",
|
||||
@@ -38,14 +38,14 @@ wayland-protocols-misc = { version = "0.3.1", features = [
|
||||
"client",
|
||||
], optional = true }
|
||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||
ashpd = { version = "0.10", default-features = false, features = [
|
||||
ashpd = { version = "0.9", default-features = false, features = [
|
||||
"tokio",
|
||||
], optional = true }
|
||||
reis = { version = "0.4", features = ["tokio"], optional = true }
|
||||
reis = { version = "0.2", features = ["tokio"], optional = true }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
bitflags = "2.6.0"
|
||||
core-graphics = { version = "0.24.0", features = ["highsierra"] }
|
||||
bitflags = "2.5.0"
|
||||
core-graphics = { version = "0.23", features = ["highsierra"] }
|
||||
keycode = "0.4.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
@@ -60,13 +60,13 @@ windows = { version = "0.58.0", features = [
|
||||
] }
|
||||
|
||||
[features]
|
||||
default = ["wlroots", "x11", "remote_desktop_portal", "libei"]
|
||||
wlroots = [
|
||||
default = ["wayland", "x11", "xdg_desktop_portal", "libei"]
|
||||
wayland = [
|
||||
"dep:wayland-client",
|
||||
"dep:wayland-protocols",
|
||||
"dep:wayland-protocols-wlr",
|
||||
"dep:wayland-protocols-misc",
|
||||
]
|
||||
x11 = ["dep:x11"]
|
||||
remote_desktop_portal = ["dep:ashpd"]
|
||||
xdg_desktop_portal = ["dep:ashpd"]
|
||||
libei = ["dep:reis", "dep:ashpd"]
|
||||
|
||||
@@ -6,35 +6,53 @@ pub enum InputEmulationError {
|
||||
Emulate(#[from] EmulationError),
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
unix,
|
||||
any(feature = "remote_desktop_portal", feature = "libei"),
|
||||
not(target_os = "macos")
|
||||
))]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use ashpd::{desktop::ResponseError, Error::Response};
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use reis::tokio::EiConvertEventStreamError;
|
||||
use std::io;
|
||||
use thiserror::Error;
|
||||
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
use wayland_client::{
|
||||
backend::WaylandError,
|
||||
globals::{BindError, GlobalError},
|
||||
ConnectError, DispatchError,
|
||||
};
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
use reis::tokio::HandshakeError;
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("error in libei stream: {inner:?}")]
|
||||
pub struct ReisConvertStreamError {
|
||||
inner: EiConvertEventStreamError,
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
impl From<EiConvertEventStreamError> for ReisConvertStreamError {
|
||||
fn from(e: EiConvertEventStreamError) -> Self {
|
||||
Self { inner: e }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum EmulationError {
|
||||
#[error("event stream closed")]
|
||||
EndOfStream,
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("libei error: `{0}`")]
|
||||
Libei(#[from] reis::Error),
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[error("libei error flushing events: `{0}`")]
|
||||
Libei(#[from] reis::event::Error),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("")]
|
||||
LibeiConvertStream(#[from] ReisConvertStreamError),
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[error("wayland error: `{0}`")]
|
||||
Wayland(#[from] wayland_client::backend::WaylandError),
|
||||
#[cfg(all(
|
||||
unix,
|
||||
any(feature = "remote_desktop_portal", feature = "libei"),
|
||||
any(feature = "xdg_desktop_portal", feature = "libei"),
|
||||
not(target_os = "macos")
|
||||
))]
|
||||
#[error("xdg-desktop-portal: `{0}`")]
|
||||
@@ -45,13 +63,13 @@ pub enum EmulationError {
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum EmulationCreationError {
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[error("wlroots backend: `{0}`")]
|
||||
Wlroots(#[from] WlrootsEmulationCreationError),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
#[error("libei backend: `{0}`")]
|
||||
Libei(#[from] LibeiEmulationCreationError),
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
#[error("xdg-desktop-portal: `{0}`")]
|
||||
Xdp(#[from] XdpEmulationCreationError),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
@@ -79,7 +97,7 @@ impl EmulationCreationError {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
if matches!(
|
||||
self,
|
||||
EmulationCreationError::Xdp(XdpEmulationCreationError::Ashpd(Response(
|
||||
@@ -92,7 +110,7 @@ impl EmulationCreationError {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlrootsEmulationCreationError {
|
||||
#[error(transparent)]
|
||||
@@ -109,7 +127,7 @@ pub enum WlrootsEmulationCreationError {
|
||||
Io(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
#[error("wayland protocol \"{protocol}\" not supported: {inner}")]
|
||||
pub struct WaylandBindError {
|
||||
@@ -117,7 +135,7 @@ pub struct WaylandBindError {
|
||||
protocol: &'static str,
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
impl WaylandBindError {
|
||||
pub(crate) fn new(inner: BindError, protocol: &'static str) -> Self {
|
||||
Self { inner, protocol }
|
||||
@@ -132,10 +150,10 @@ pub enum LibeiEmulationCreationError {
|
||||
#[error(transparent)]
|
||||
Io(#[from] std::io::Error),
|
||||
#[error(transparent)]
|
||||
Reis(#[from] reis::Error),
|
||||
Handshake(#[from] HandshakeError),
|
||||
}
|
||||
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
#[derive(Debug, Error)]
|
||||
pub enum XdpEmulationCreationError {
|
||||
#[error(transparent)]
|
||||
|
||||
@@ -14,10 +14,10 @@ mod windows;
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
mod x11;
|
||||
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
mod wlroots;
|
||||
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
mod xdg_desktop_portal;
|
||||
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
@@ -34,11 +34,11 @@ pub type EmulationHandle = u64;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum Backend {
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Wlroots,
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Libei,
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
Xdp,
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
X11,
|
||||
@@ -52,11 +52,11 @@ pub enum Backend {
|
||||
impl Display for Backend {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::Wlroots => write!(f, "wlroots"),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::Libei => write!(f, "libei"),
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
Backend::Xdp => write!(f, "xdg-desktop-portal"),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11 => write!(f, "X11"),
|
||||
@@ -78,13 +78,13 @@ pub struct InputEmulation {
|
||||
impl InputEmulation {
|
||||
async fn with_backend(backend: Backend) -> Result<InputEmulation, EmulationCreationError> {
|
||||
let emulation: Box<dyn Emulation> = match backend {
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::Wlroots => Box::new(wlroots::WlrootsEmulation::new()?),
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::Libei => Box::new(libei::LibeiEmulation::new().await?),
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11 => Box::new(x11::X11Emulation::new()?),
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
Backend::Xdp => Box::new(xdg_desktop_portal::DesktopPortalEmulation::new().await?),
|
||||
#[cfg(windows)]
|
||||
Backend::Windows => Box::new(windows::WindowsEmulation::new()?),
|
||||
@@ -109,11 +109,11 @@ impl InputEmulation {
|
||||
}
|
||||
|
||||
for backend in [
|
||||
#[cfg(all(unix, feature = "wlroots", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Backend::Wlroots,
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Backend::Libei,
|
||||
#[cfg(all(unix, feature = "remote_desktop_portal", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
Backend::Xdp,
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
Backend::X11,
|
||||
|
||||
@@ -1,18 +1,23 @@
|
||||
use futures::{future, StreamExt};
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
io,
|
||||
os::{fd::OwnedFd, unix::net::UnixStream},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
atomic::{AtomicBool, AtomicU32, Ordering},
|
||||
Arc, Mutex, RwLock,
|
||||
},
|
||||
time::{SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use ashpd::desktop::{
|
||||
remote_desktop::{DeviceType, RemoteDesktop},
|
||||
PersistMode, Session,
|
||||
use ashpd::{
|
||||
desktop::{
|
||||
remote_desktop::{DeviceType, RemoteDesktop},
|
||||
PersistMode, Session,
|
||||
},
|
||||
WindowIdentifier,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -21,16 +26,32 @@ use reis::{
|
||||
self, button::ButtonState, handshake::ContextType, keyboard::KeyState, Button, Keyboard,
|
||||
Pointer, Scroll,
|
||||
},
|
||||
event::{self, Connection, DeviceCapability, DeviceEvent, EiEvent, SeatEvent},
|
||||
tokio::EiConvertEventStream,
|
||||
event::{DeviceCapability, DeviceEvent, EiEvent, SeatEvent},
|
||||
tokio::{ei_handshake, EiConvertEventStream, EiEventStream},
|
||||
};
|
||||
|
||||
use input_event::{Event, KeyboardEvent, PointerEvent};
|
||||
|
||||
use crate::error::EmulationError;
|
||||
use crate::error::{EmulationError, ReisConvertStreamError};
|
||||
|
||||
use super::{error::LibeiEmulationCreationError, Emulation, EmulationHandle};
|
||||
|
||||
static INTERFACES: Lazy<HashMap<&'static str, u32>> = Lazy::new(|| {
|
||||
let mut m = HashMap::new();
|
||||
m.insert("ei_connection", 1);
|
||||
m.insert("ei_callback", 1);
|
||||
m.insert("ei_pingpong", 1);
|
||||
m.insert("ei_seat", 1);
|
||||
m.insert("ei_device", 2);
|
||||
m.insert("ei_pointer", 1);
|
||||
m.insert("ei_pointer_absolute", 1);
|
||||
m.insert("ei_scroll", 1);
|
||||
m.insert("ei_button", 1);
|
||||
m.insert("ei_keyboard", 1);
|
||||
m.insert("ei_touchscreen", 1);
|
||||
m
|
||||
});
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Devices {
|
||||
pointer: Arc<RwLock<Option<(ei::Device, ei::Pointer)>>>,
|
||||
@@ -41,11 +62,11 @@ struct Devices {
|
||||
|
||||
pub(crate) struct LibeiEmulation<'a> {
|
||||
context: ei::Context,
|
||||
conn: event::Connection,
|
||||
devices: Devices,
|
||||
ei_task: JoinHandle<()>,
|
||||
error: Arc<Mutex<Option<EmulationError>>>,
|
||||
libei_error: Arc<AtomicBool>,
|
||||
serial: AtomicU32,
|
||||
_remote_desktop: RemoteDesktop<'a>,
|
||||
session: Session<'a, RemoteDesktop<'a>>,
|
||||
}
|
||||
@@ -68,7 +89,10 @@ async fn get_ei_fd<'a>(
|
||||
.await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
let _devices = remote_desktop.start(&session, None).await?.response()?;
|
||||
let _devices = remote_desktop
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
let fd = remote_desktop.connect_to_eis(&session).await?;
|
||||
Ok((remote_desktop, session, fd))
|
||||
@@ -80,15 +104,20 @@ impl<'a> LibeiEmulation<'a> {
|
||||
let stream = UnixStream::from(eifd);
|
||||
stream.set_nonblocking(true)?;
|
||||
let context = ei::Context::new(stream)?;
|
||||
let (conn, events) = context
|
||||
.handshake_tokio("de.feschber.LanMouse", ContextType::Sender)
|
||||
.await?;
|
||||
let mut events = EiEventStream::new(context.clone())?;
|
||||
let handshake = ei_handshake(
|
||||
&mut events,
|
||||
"de.feschber.LanMouse",
|
||||
ContextType::Sender,
|
||||
&INTERFACES,
|
||||
)
|
||||
.await?;
|
||||
let events = EiConvertEventStream::new(events, handshake.serial);
|
||||
let devices = Devices::default();
|
||||
let libei_error = Arc::new(AtomicBool::default());
|
||||
let error = Arc::new(Mutex::new(None));
|
||||
let ei_handler = ei_task(
|
||||
events,
|
||||
conn.clone(),
|
||||
context.clone(),
|
||||
devices.clone(),
|
||||
libei_error.clone(),
|
||||
@@ -96,13 +125,15 @@ impl<'a> LibeiEmulation<'a> {
|
||||
);
|
||||
let ei_task = tokio::task::spawn_local(ei_handler);
|
||||
|
||||
let serial = AtomicU32::new(handshake.serial);
|
||||
|
||||
Ok(Self {
|
||||
context,
|
||||
conn,
|
||||
devices,
|
||||
ei_task,
|
||||
error,
|
||||
libei_error,
|
||||
serial,
|
||||
_remote_desktop,
|
||||
session,
|
||||
})
|
||||
@@ -138,7 +169,7 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
let pointer_device = self.devices.pointer.read().unwrap();
|
||||
if let Some((d, p)) = pointer_device.as_ref() {
|
||||
p.motion_relative(dx as f32, dy as f32);
|
||||
d.frame(self.conn.serial(), now);
|
||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
||||
}
|
||||
}
|
||||
PointerEvent::Button {
|
||||
@@ -155,7 +186,7 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
_ => ButtonState::Press,
|
||||
},
|
||||
);
|
||||
d.frame(self.conn.serial(), now);
|
||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
||||
}
|
||||
}
|
||||
PointerEvent::Axis {
|
||||
@@ -169,7 +200,7 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
0 => s.scroll(0., value as f32),
|
||||
_ => s.scroll(value as f32, 0.),
|
||||
}
|
||||
d.frame(self.conn.serial(), now);
|
||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
||||
}
|
||||
}
|
||||
PointerEvent::AxisDiscrete120 { axis, value } => {
|
||||
@@ -179,7 +210,7 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
0 => s.scroll_discrete(0, value),
|
||||
_ => s.scroll_discrete(value, 0),
|
||||
}
|
||||
d.frame(self.conn.serial(), now);
|
||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -198,7 +229,7 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
_ => KeyState::Press,
|
||||
},
|
||||
);
|
||||
d.frame(self.conn.serial(), now);
|
||||
d.frame(self.serial.load(Ordering::SeqCst), now);
|
||||
}
|
||||
}
|
||||
KeyboardEvent::Modifiers { .. } => {}
|
||||
@@ -221,7 +252,6 @@ impl<'a> Emulation for LibeiEmulation<'a> {
|
||||
|
||||
async fn ei_task(
|
||||
mut events: EiConvertEventStream,
|
||||
_conn: Connection,
|
||||
context: ei::Context,
|
||||
devices: Devices,
|
||||
libei_error: Arc<AtomicBool>,
|
||||
@@ -246,7 +276,11 @@ async fn ei_event_handler(
|
||||
devices: &Devices,
|
||||
) -> Result<(), EmulationError> {
|
||||
loop {
|
||||
let event = events.next().await.ok_or(EmulationError::EndOfStream)??;
|
||||
let event = events
|
||||
.next()
|
||||
.await
|
||||
.ok_or(EmulationError::EndOfStream)?
|
||||
.map_err(ReisConvertStreamError::from)?;
|
||||
const CAPABILITIES: &[DeviceCapability] = &[
|
||||
DeviceCapability::Pointer,
|
||||
DeviceCapability::PointerAbsolute,
|
||||
|
||||
@@ -4,6 +4,7 @@ use ashpd::{
|
||||
PersistMode, Session,
|
||||
},
|
||||
zbus::AsyncDrop,
|
||||
WindowIdentifier,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -42,7 +43,10 @@ impl<'a> DesktopPortalEmulation<'a> {
|
||||
.await?;
|
||||
|
||||
log::info!("requesting permission for input emulation");
|
||||
let _devices = proxy.start(&session, None).await?.response()?;
|
||||
let _devices = proxy
|
||||
.start(&session, &WindowIdentifier::default())
|
||||
.await?
|
||||
.response()?;
|
||||
|
||||
log::debug!("started session");
|
||||
let session = session;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "input-event"
|
||||
description = "cross-platform input-event types for input-capture / input-emulation"
|
||||
version = "0.3.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
@@ -11,10 +11,10 @@ futures-core = "0.3.30"
|
||||
log = "0.4.22"
|
||||
num_enum = "0.7.2"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
thiserror = "2.0.0"
|
||||
thiserror = "1.0.61"
|
||||
|
||||
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
||||
reis = { version = "0.4", optional = true }
|
||||
reis = { version = "0.2.0", optional = true }
|
||||
|
||||
[features]
|
||||
default = ["libei"]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
[package]
|
||||
name = "lan-mouse-cli"
|
||||
description = "CLI Frontend for lan-mouse"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
|
||||
[dependencies]
|
||||
futures = "0.3.30"
|
||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
|
||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.1.0" }
|
||||
tokio = { version = "1.32.0", features = [
|
||||
"io-util",
|
||||
"io-std",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "lan-mouse-gtk"
|
||||
description = "GTK4 / Libadwaita Frontend for lan-mouse"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
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" }
|
||||
hostname = "0.4.0"
|
||||
log = "0.4.20"
|
||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.2.0" }
|
||||
lan-mouse-ipc = { path = "../lan-mouse-ipc", version = "0.1.0" }
|
||||
|
||||
[build-dependencies]
|
||||
glib-build-tools = { version = "0.20.0" }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "lan-mouse-ipc"
|
||||
description = "library for communication between lan-mouse service and frontends"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
@@ -11,6 +11,6 @@ futures = "0.3.30"
|
||||
log = "0.4.22"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.107"
|
||||
thiserror = "2.0.0"
|
||||
thiserror = "1.0.63"
|
||||
tokio = { version = "1.32.0", features = ["net", "io-util", "time"] }
|
||||
tokio-stream = { version = "0.1.15", features = ["io-util"] }
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
[package]
|
||||
name = "lan-mouse-proto"
|
||||
description = "network protocol for lan-mouse"
|
||||
version = "0.2.0"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/feschber/lan-mouse"
|
||||
|
||||
[dependencies]
|
||||
num_enum = "0.7.2"
|
||||
thiserror = "2.0.0"
|
||||
input-event = { path = "../input-event", version = "0.3.0" }
|
||||
thiserror = "1.0.61"
|
||||
input-event = { path = "../input-event", version = "0.2.1" }
|
||||
paste = "1.0"
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 46 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 48 KiB |
@@ -85,33 +85,27 @@ struct CliArgs {
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
||||
pub enum CaptureBackend {
|
||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
||||
#[serde(rename = "input-capture-portal")]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
InputCapturePortal,
|
||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
||||
#[serde(rename = "layer-shell")]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
LayerShell,
|
||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
||||
#[serde(rename = "x11")]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
X11,
|
||||
#[cfg(windows)]
|
||||
#[serde(rename = "windows")]
|
||||
Windows,
|
||||
#[cfg(target_os = "macos")]
|
||||
#[serde(rename = "macos")]
|
||||
MacOs,
|
||||
#[serde(rename = "dummy")]
|
||||
Dummy,
|
||||
}
|
||||
|
||||
impl Display for CaptureBackend {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
CaptureBackend::InputCapturePortal => write!(f, "input-capture-portal"),
|
||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
CaptureBackend::LayerShell => write!(f, "layer-shell"),
|
||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
CaptureBackend::X11 => write!(f, "X11"),
|
||||
#[cfg(windows)]
|
||||
CaptureBackend::Windows => write!(f, "windows"),
|
||||
@@ -125,11 +119,11 @@ impl Display for CaptureBackend {
|
||||
impl From<CaptureBackend> for input_capture::Backend {
|
||||
fn from(backend: CaptureBackend) -> Self {
|
||||
match backend {
|
||||
#[cfg(all(unix, feature = "libei_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
CaptureBackend::InputCapturePortal => Self::InputCapturePortal,
|
||||
#[cfg(all(unix, feature = "layer_shell_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
CaptureBackend::LayerShell => Self::LayerShell,
|
||||
#[cfg(all(unix, feature = "x11_capture", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
CaptureBackend::X11 => Self::X11,
|
||||
#[cfg(windows)]
|
||||
CaptureBackend::Windows => Self::Windows,
|
||||
@@ -142,38 +136,31 @@ impl From<CaptureBackend> for input_capture::Backend {
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, ValueEnum)]
|
||||
pub enum EmulationBackend {
|
||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
||||
#[serde(rename = "wlroots")]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
Wlroots,
|
||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
||||
#[serde(rename = "libei")]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
Libei,
|
||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
||||
#[serde(rename = "xdp")]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
Xdp,
|
||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
||||
#[serde(rename = "x11")]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
X11,
|
||||
#[cfg(windows)]
|
||||
#[serde(rename = "windows")]
|
||||
Windows,
|
||||
#[cfg(target_os = "macos")]
|
||||
#[serde(rename = "macos")]
|
||||
MacOs,
|
||||
#[serde(rename = "dummy")]
|
||||
Dummy,
|
||||
}
|
||||
|
||||
impl From<EmulationBackend> for input_emulation::Backend {
|
||||
fn from(backend: EmulationBackend) -> Self {
|
||||
match backend {
|
||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
EmulationBackend::Wlroots => Self::Wlroots,
|
||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
EmulationBackend::Libei => Self::Libei,
|
||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
EmulationBackend::Xdp => Self::Xdp,
|
||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
EmulationBackend::X11 => Self::X11,
|
||||
#[cfg(windows)]
|
||||
EmulationBackend::Windows => Self::Windows,
|
||||
@@ -187,13 +174,13 @@ impl From<EmulationBackend> for input_emulation::Backend {
|
||||
impl Display for EmulationBackend {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
#[cfg(all(unix, feature = "wlroots_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "wayland", not(target_os = "macos")))]
|
||||
EmulationBackend::Wlroots => write!(f, "wlroots"),
|
||||
#[cfg(all(unix, feature = "libei_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "libei", not(target_os = "macos")))]
|
||||
EmulationBackend::Libei => write!(f, "libei"),
|
||||
#[cfg(all(unix, feature = "rdp_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "xdg_desktop_portal", not(target_os = "macos")))]
|
||||
EmulationBackend::Xdp => write!(f, "xdg-desktop-portal"),
|
||||
#[cfg(all(unix, feature = "x11_emulation", not(target_os = "macos")))]
|
||||
#[cfg(all(unix, feature = "x11", not(target_os = "macos")))]
|
||||
EmulationBackend::X11 => write!(f, "X11"),
|
||||
#[cfg(windows)]
|
||||
EmulationBackend::Windows => write!(f, "windows"),
|
||||
@@ -206,9 +193,7 @@ impl Display for EmulationBackend {
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, ValueEnum)]
|
||||
pub enum Frontend {
|
||||
#[serde(rename = "gtk")]
|
||||
Gtk,
|
||||
#[serde(rename = "cli")]
|
||||
Cli,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user