Skip to content

Commit

Permalink
Ei protocol support using reis
Browse files Browse the repository at this point in the history
The Ei protocol is needed for the xdg-desktop-portal `RemoteDesktop`
portal to emulate input devices, as well as by the `InputCapture` portal
for Synergy-like uses (input-leap supports Wayland with this portal).

This is quite incomplete, but the `type-text` example in `reis` now
works in Anvil. Reis could still use somewhat better higher-level
servere-side APIs.

It might make sense if ei exposed seats and devices matching those in
Smithay (or would compositors not always want to do that?). Not sure how
best to handle that.

Receiver contexts for the `InputCapture` portal are also a bit more
complicated to implement. Those involve capturing input once the cursor
crosses outside the display. That isn't implemented at all here yet.
  • Loading branch information
ids1024 committed Sep 11, 2024
1 parent f364c73 commit 4a20e03
Show file tree
Hide file tree
Showing 7 changed files with 605 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ encoding_rs = { version = "0.8.33", optional = true }
profiling = "1.0"
smallvec = "1.11"
pixman = { version = "0.1.0", features = ["drm-fourcc"], optional = true }

reis = { git = "https://github.com/ids1024/reis", features = ["calloop"] }

[dev-dependencies]
clap = { version = "4", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions anvil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub mod cursor;
pub mod drawing;
pub mod focus;
pub mod input_handler;
pub mod libei;
pub mod render;
pub mod shell;
pub mod state;
Expand Down
32 changes: 32 additions & 0 deletions anvil/src/libei.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use reis::calloop::EisListenerSource;
use reis::eis;
use smithay::reexports::reis;

use smithay::backend::libei::EiInput;
use smithay::reexports::calloop;

use crate::state::AnvilState;
use crate::udev::UdevData;

pub fn listen_eis(handle: &calloop::LoopHandle<'static, AnvilState<UdevData>>) {
let path = reis::default_socket_path().unwrap();
std::fs::remove_file(&path); // XXX in use?
let listener = eis::Listener::bind(&path).unwrap();
let listener_source = EisListenerSource::new(listener);

std::env::set_var("LIBEI_SOCKET", path);

let handle_clone = handle.clone();
handle
.insert_source(listener_source, move |context, _, _| {
let source = EiInput::new(context);
handle_clone
.insert_source(source, |event, _, data| {
let dh = data.display_handle.clone();
data.process_input_event(&dh, event);
})
.unwrap();
Ok(calloop::PostAction::Continue)
})
.unwrap();
}
2 changes: 2 additions & 0 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ pub fn run_udev() {
#[cfg(feature = "xwayland")]
state.start_xwayland();

crate::libei::listen_eis(&event_loop.handle());

/*
* And run our loop
*/
Expand Down
Loading

0 comments on commit 4a20e03

Please sign in to comment.