mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-16 09:40:54 +03:00
committed by
GitHub
parent
65a12735e2
commit
fed8e02d9f
695
Cargo.lock
generated
695
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
13
Cargo.toml
13
Cargo.toml
@@ -16,7 +16,7 @@ lto = "fat"
|
||||
tempfile = "3.8"
|
||||
trust-dns-resolver = "0.23"
|
||||
memmap = "0.7"
|
||||
toml = "0.7"
|
||||
toml = "0.8"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
anyhow = "1.0.71"
|
||||
log = "0.4.20"
|
||||
@@ -29,10 +29,10 @@ futures = "0.3.28"
|
||||
clap = { version="4.4.11", features = ["derive"] }
|
||||
|
||||
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
|
||||
wayland-client = { version="0.30.2", optional = true }
|
||||
wayland-protocols = { version="0.30.0", features=["client", "staging", "unstable"], optional = true }
|
||||
wayland-protocols-wlr = { version="0.1.0", features=["client"], optional = true }
|
||||
wayland-protocols-misc = { version="0.1.0", features=["client"], optional = true }
|
||||
wayland-client = { version="0.31.1", optional = true }
|
||||
wayland-protocols = { version="0.31.0", features=["client", "staging", "unstable"], optional = true }
|
||||
wayland-protocols-wlr = { version="0.2.0", features=["client"], optional = true }
|
||||
wayland-protocols-misc = { version="0.2.0", features=["client"], optional = true }
|
||||
x11 = { version = "2.21.0", features = ["xlib", "xtest"], optional = true }
|
||||
ashpd = { version = "0.6.2", default-features = false, features = ["tokio"], optional = true }
|
||||
reis = { git = "https://github.com/ids1024/reis", features = [ "tokio" ], optional = true }
|
||||
@@ -41,6 +41,7 @@ libc = { version="0.2.148", optional = true }
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_6"], optional = true }
|
||||
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_1"], optional = true }
|
||||
async-channel = { version = "2.1.1", optional = true }
|
||||
|
||||
[target.'cfg(target_os="macos")'.dependencies]
|
||||
core-graphics = { version = "0.23", features = ["highsierra"] }
|
||||
@@ -57,4 +58,4 @@ wayland = ["dep:wayland-client", "dep:wayland-protocols", "dep:wayland-protocols
|
||||
x11 = ["dep:x11"]
|
||||
xdg_desktop_portal = ["dep:ashpd"]
|
||||
libei = ["dep:reis", "dep:ashpd", "dep:libc" ]
|
||||
gtk = ["dep:gtk", "dep:adw"]
|
||||
gtk = ["dep:gtk", "dep:adw", "dep:async-channel"]
|
||||
|
||||
@@ -193,7 +193,7 @@ impl EventConsumer for LibeiConsumer {
|
||||
};
|
||||
let event = match event {
|
||||
PendingRequestResult::Request(result) => result,
|
||||
PendingRequestResult::ProtocolError(e) => {
|
||||
PendingRequestResult::ParseError(e) => {
|
||||
return Err(anyhow!("libei protocol violation: {e}"))
|
||||
}
|
||||
PendingRequestResult::InvalidObject(e) => return Err(anyhow!("invalid object {e}")),
|
||||
|
||||
@@ -3,8 +3,7 @@ use crate::consumer::EventConsumer;
|
||||
use async_trait::async_trait;
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::os::fd::OwnedFd;
|
||||
use std::os::unix::prelude::AsRawFd;
|
||||
use std::os::fd::{AsFd, OwnedFd};
|
||||
use wayland_client::backend::WaylandError;
|
||||
use wayland_client::WEnum;
|
||||
|
||||
@@ -95,7 +94,7 @@ impl State {
|
||||
|
||||
// TODO: use server side keymap
|
||||
if let Some((format, fd, size)) = self.keymap.as_ref() {
|
||||
keyboard.keymap(*format, fd.as_raw_fd(), *size);
|
||||
keyboard.keymap(*format, fd.as_fd(), *size);
|
||||
} else {
|
||||
panic!("no keymap");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::{
|
||||
collections::VecDeque,
|
||||
env,
|
||||
io::{self, ErrorKind},
|
||||
os::fd::{OwnedFd, RawFd},
|
||||
os::fd::{AsFd, OwnedFd, RawFd},
|
||||
pin::Pin,
|
||||
task::{ready, Context, Poll},
|
||||
};
|
||||
@@ -145,7 +145,7 @@ impl Window {
|
||||
draw(&mut file, (width, height));
|
||||
let pool = g
|
||||
.shm
|
||||
.create_pool(file.as_raw_fd(), (width * height * 4) as i32, qh, ());
|
||||
.create_pool(file.as_fd(), (width * height * 4) as i32, qh, ());
|
||||
let buffer = pool.create_buffer(
|
||||
0,
|
||||
width as i32,
|
||||
@@ -324,7 +324,7 @@ impl WaylandEventProducer {
|
||||
queue.flush()?;
|
||||
|
||||
// prepare reading wayland events
|
||||
let read_guard = queue.prepare_read()?;
|
||||
let read_guard = queue.prepare_read().unwrap(); // there can not yet be events to dispatch
|
||||
let wayland_fd = read_guard.connection_fd().try_clone_to_owned().unwrap();
|
||||
std::mem::drop(read_guard);
|
||||
|
||||
@@ -366,7 +366,15 @@ impl WaylandEventProducer {
|
||||
log::debug!("{:#?}", i.1);
|
||||
}
|
||||
|
||||
let read_guard = queue.prepare_read()?;
|
||||
let read_guard = loop {
|
||||
match queue.prepare_read() {
|
||||
Some(r) => break r,
|
||||
None => {
|
||||
queue.dispatch_pending(&mut state)?;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
};
|
||||
state.read_guard = Some(read_guard);
|
||||
|
||||
let inner = AsyncFd::new(Inner { queue, state })?;
|
||||
@@ -484,16 +492,20 @@ impl Inner {
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_read(&mut self) {
|
||||
match self.queue.prepare_read() {
|
||||
Ok(r) => self.state.read_guard = Some(r),
|
||||
Err(WaylandError::Io(e)) => {
|
||||
log::error!("error preparing read from wayland socket: {e}")
|
||||
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(());
|
||||
}
|
||||
}
|
||||
Err(WaylandError::Protocol(e)) => {
|
||||
panic!("wayland Protocol violation: {e}")
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn dispatch_events(&mut self) {
|
||||
@@ -579,7 +591,10 @@ impl Stream for WaylandEventProducer {
|
||||
// read events
|
||||
while inner.read() {
|
||||
// prepare next read
|
||||
inner.prepare_read();
|
||||
match inner.prepare_read() {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Poll::Ready(Some(Err(e))),
|
||||
}
|
||||
}
|
||||
|
||||
// dispatch the events
|
||||
@@ -589,7 +604,10 @@ impl Stream for WaylandEventProducer {
|
||||
inner.flush_events();
|
||||
|
||||
// prepare for the next read
|
||||
inner.prepare_read();
|
||||
match inner.prepare_read() {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Poll::Ready(Some(Err(e))),
|
||||
}
|
||||
}
|
||||
|
||||
// clear read readiness for tokio read guard
|
||||
|
||||
@@ -14,7 +14,7 @@ use adw::Application;
|
||||
use gtk::{
|
||||
gdk::Display,
|
||||
gio::{SimpleAction, SimpleActionGroup},
|
||||
glib::{clone, MainContext, Priority},
|
||||
glib::clone,
|
||||
prelude::*,
|
||||
subclass::prelude::ObjectSubclassIsExt,
|
||||
CssProvider, IconTheme,
|
||||
@@ -81,7 +81,7 @@ fn build_ui(app: &Application) {
|
||||
};
|
||||
log::debug!("connected to lan-mouse-socket");
|
||||
|
||||
let (sender, receiver) = MainContext::channel::<FrontendNotify>(Priority::default());
|
||||
let (sender, receiver) = async_channel::bounded(10);
|
||||
|
||||
gio::spawn_blocking(move || {
|
||||
match loop {
|
||||
@@ -105,7 +105,7 @@ fn build_ui(app: &Application) {
|
||||
// parse json
|
||||
let json = str::from_utf8(&buf).unwrap();
|
||||
match serde_json::from_str(json) {
|
||||
Ok(notify) => sender.send(notify).unwrap(),
|
||||
Ok(notify) => sender.send_blocking(notify).unwrap(),
|
||||
Err(e) => log::error!("{e}"),
|
||||
}
|
||||
} {
|
||||
@@ -116,8 +116,9 @@ fn build_ui(app: &Application) {
|
||||
|
||||
let window = Window::new(app);
|
||||
window.imp().stream.borrow_mut().replace(tx);
|
||||
receiver.attach(None, clone!(@weak window => @default-return glib::ControlFlow::Break,
|
||||
move |notify| {
|
||||
glib::spawn_future_local(clone!(@weak window => async move {
|
||||
loop {
|
||||
let notify = receiver.recv().await.unwrap();
|
||||
match notify {
|
||||
FrontendNotify::NotifyClientCreate(client, hostname, port, position) => {
|
||||
window.new_client(client, hostname, port, position, false);
|
||||
@@ -158,9 +159,8 @@ fn build_ui(app: &Application) {
|
||||
window.imp().set_port(port);
|
||||
}
|
||||
}
|
||||
glib::ControlFlow::Continue
|
||||
}
|
||||
));
|
||||
}));
|
||||
|
||||
let action_request_client_update =
|
||||
SimpleAction::new("request-client-update", Some(&u32::static_variant_type()));
|
||||
|
||||
Reference in New Issue
Block a user