diff --git a/Cargo.toml b/Cargo.toml index 30f77ae..0092225 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,6 @@ default-members = ["qemu-rdw"] zbus = { git = 'https://gitlab.freedesktop.org/elmarco/zbus.git', branch = 'proxy-prop' } zvariant = { git = 'https://gitlab.freedesktop.org/elmarco/zbus.git', branch = 'proxy-prop' } vnc = { git = 'https://github.com/elmarco/rust-vnc', branch = 'server' } + +[patch."https://gitlab.gnome.org/malureau/rdw.git"] +rdw = { path = '/home/elmarco/src/rdw/rdw' } diff --git a/qemu-display-listener/Cargo.toml b/qemu-display-listener/Cargo.toml index 48681dd..8c1f985 100644 --- a/qemu-display-listener/Cargo.toml +++ b/qemu-display-listener/Cargo.toml @@ -12,9 +12,10 @@ derivative = "2.2.0" zbus = { version = "2.0.0-beta", features = ["xml"] } zvariant = { version = "2.4.0", features = ["serde_bytes"] } libc = "0.2.86" -glib = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } +glib = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true } enumflags2 = { version = "0.6.4", features = ["serde"] } serde = { version = "1.0.123", features = ["derive"] } serde_repr = "0.1.6" serde_bytes = "0.11.5" futures-util = { version = "0.3.8", features = ["async-await-macro"] } +once_cell = "1.5" diff --git a/qemu-display-listener/src/audio.rs b/qemu-display-listener/src/audio.rs index 5d34cfd..5c9be10 100644 --- a/qemu-display-listener/src/audio.rs +++ b/qemu-display-listener/src/audio.rs @@ -1,4 +1,5 @@ -use std::cell::RefCell; +use once_cell::sync::OnceCell; +use std::default::Default; use std::os::unix::net::UnixStream; use std::str::FromStr; use std::sync::mpsc::{self, Receiver, SendError}; @@ -68,22 +69,24 @@ pub struct Audio { #[derive(Debug)] pub(crate) struct AudioOutListener> { tx: E, - err: Arc>>>, + err: Arc>>, } impl> AudioOutListener { pub(crate) fn new(tx: E) -> Self { - let err = Arc::new(RefCell::new(None)); - AudioOutListener { tx, err } + AudioOutListener { + tx, + err: Default::default(), + } } fn send(&mut self, event: AudioOutEvent) { if let Err(e) = self.tx.send_event(event) { - *self.err.borrow_mut() = Some(e); + let _ = self.err.set(e); } } - pub fn err(&self) -> Arc>>> { + pub fn err(&self) -> Arc>> { self.err.clone() } } @@ -151,22 +154,24 @@ impl> AudioOutListener { #[derive(Debug)] pub(crate) struct AudioInListener> { tx: E, - err: Arc>>>, + err: Arc>>, } impl> AudioInListener { pub(crate) fn new(tx: E) -> Self { - let err = Arc::new(RefCell::new(None)); - AudioInListener { tx, err } + AudioInListener { + tx, + err: Default::default(), + } } fn send(&mut self, event: AudioInEvent) { if let Err(e) = self.tx.send_event(event) { - *self.err.borrow_mut() = Some(e); + let _ = self.err.set(e); } } - pub fn err(&self) -> Arc>>> { + pub fn err(&self) -> Arc>> { self.err.clone() } } @@ -237,7 +242,11 @@ impl Audio { pub fn available(conn: &zbus::Connection) -> bool { // TODO: we may want to generalize interface detection - let ip = zbus::fdo::IntrospectableProxy::new_for(&conn, "org.qemu", "/org/qemu/Display1") + let ip = zbus::fdo::IntrospectableProxy::builder(conn) + .destination("org.qemu") + .path("/org/qemu/Display1") + .unwrap() + .build() .unwrap(); let introspect = zbus::xml::Node::from_str(&ip.introspect().unwrap()).unwrap(); let has_audio = introspect @@ -264,7 +273,7 @@ impl Audio { eprintln!("Listener DBus error: {}", e); return; } - if let Some(e) = &*err.borrow() { + if let Some(e) = err.get() { eprintln!("Listener channel error: {}", e); return; } @@ -291,7 +300,7 @@ impl Audio { eprintln!("Listener DBus error: {}", e); return; } - if let Some(e) = &*err.borrow() { + if let Some(e) = err.get() { eprintln!("Listener channel error: {}", e); return; } diff --git a/qemu-display-listener/src/console.rs b/qemu-display-listener/src/console.rs index d60dea0..52e1a76 100644 --- a/qemu-display-listener/src/console.rs +++ b/qemu-display-listener/src/console.rs @@ -1,11 +1,15 @@ +use std::convert::TryFrom; use std::os::unix::net::UnixStream; use std::sync::mpsc::{self, Receiver, Sender}; use std::{os::unix::io::AsRawFd, thread}; -use zbus::{dbus_proxy, export::zvariant::Fd}; +use zbus::{ + dbus_proxy, + export::zvariant::{Fd, ObjectPath}, +}; use crate::Result; -use crate::{ConsoleEvent, ConsoleListener, AsyncKeyboardProxy, AsyncMouseProxy}; +use crate::{AsyncKeyboardProxy, AsyncMouseProxy, ConsoleEvent, ConsoleListener}; #[dbus_proxy(default_service = "org.qemu", interface = "org.qemu.Display1.Console")] pub trait Console { @@ -53,13 +57,19 @@ pub struct Console { impl Console { pub async fn new(conn: &zbus::azync::Connection, idx: u32) -> Result { - let obj_path = format!("/org/qemu/Display1/Console_{}", idx); - let mut proxy = AsyncConsoleProxy::new_for_owned_path(conn.clone(), obj_path.clone())?; - proxy.cache_properties().await; - let mut keyboard = AsyncKeyboardProxy::new_for_owned_path(conn.clone(), obj_path.clone())?; - keyboard.cache_properties().await; - let mut mouse = AsyncMouseProxy::new_for_owned_path(conn.clone(), obj_path)?; - mouse.cache_properties().await; + let obj_path = ObjectPath::try_from(format!("/org/qemu/Display1/Console_{}", idx))?; + let proxy = AsyncConsoleProxy::builder(conn) + .path(&obj_path)? + .build_async() + .await?; + let keyboard = AsyncKeyboardProxy::builder(conn) + .path(&obj_path)? + .build_async() + .await?; + let mouse = AsyncMouseProxy::builder(conn) + .path(&obj_path)? + .build_async() + .await?; Ok(Self { proxy, keyboard, @@ -121,7 +131,7 @@ impl Console { eprintln!("Listener DBus error: {}", e); return; } - if let Some(e) = &*err.borrow() { + if let Some(e) = err.get() { eprintln!("Listener channel error: {}", e); return; } @@ -151,7 +161,7 @@ impl Console { eprintln!("Listener DBus error: {}", e); break; } - if let Some(e) = &*err.borrow() { + if let Some(e) = err.get() { eprintln!("Listener channel error: {}", e); break; } diff --git a/qemu-display-listener/src/console_listener.rs b/qemu-display-listener/src/console_listener.rs index fc2e793..91108d6 100644 --- a/qemu-display-listener/src/console_listener.rs +++ b/qemu-display-listener/src/console_listener.rs @@ -1,4 +1,4 @@ -use std::cell::RefCell; +use once_cell::sync::OnceCell; use std::ops::Drop; use std::os::unix::io::IntoRawFd; use std::os::unix::io::{AsRawFd, RawFd}; @@ -95,7 +95,7 @@ pub enum ConsoleEvent { pub(crate) struct ConsoleListener> { tx: E, wait_rx: Receiver<()>, - err: Arc>>>, + err: Arc>>, } #[dbus_interface(name = "org.qemu.Display1.Listener")] @@ -186,13 +186,16 @@ impl> ConsoleListener { impl> ConsoleListener { pub(crate) fn new(tx: E, wait_rx: Receiver<()>) -> Self { - let err = Arc::new(RefCell::new(None)); - ConsoleListener { tx, wait_rx, err } + ConsoleListener { + tx, + wait_rx, + err: Default::default(), + } } fn send(&mut self, event: ConsoleEvent) { if let Err(e) = self.tx.send_event(event) { - *self.err.borrow_mut() = Some(e); + let _ = self.err.set(e); } } @@ -200,7 +203,7 @@ impl> ConsoleListener { self.wait_rx.recv() } - pub fn err(&self) -> Arc>>> { + pub fn err(&self) -> Arc>> { self.err.clone() } } diff --git a/qemu-rdw/src/display_qemu.rs b/qemu-rdw/src/display_qemu.rs index 6747dbe..041de37 100644 --- a/qemu-rdw/src/display_qemu.rs +++ b/qemu-rdw/src/display_qemu.rs @@ -58,20 +58,16 @@ mod imp { obj.set_mouse_absolute(true); - obj.connect_key_press(clone!(@weak obj => move |_, keyval, keycode| { - log::debug!("key-press: {:?}", (keyval, keycode)); + obj.connect_key_event(clone!(@weak obj => move |_, keyval, keycode, event| { + log::debug!("key-event: {:?}", (keyval, keycode, event)); if let Some(qnum) = KEYMAP_XORGEVDEV2QNUM.get(keycode as usize) { MainContext::default().spawn_local(clone!(@weak obj => async move { - let _ = obj.console().keyboard.press(*qnum as u32).await; - })); - } - })); - - obj.connect_key_release(clone!(@weak obj => move |_, keyval, keycode| { - log::debug!("key-release: {:?}", (keyval, keycode)); - if let Some(qnum) = KEYMAP_XORGEVDEV2QNUM.get(keycode as usize) { - MainContext::default().spawn_local(clone!(@weak obj => async move { - let _ = obj.console().keyboard.release(*qnum as u32).await; + if event.contains(rdw::KeyEvent::PRESS) { + let _ = obj.console().keyboard.press(*qnum as u32).await; + } + if event.contains(rdw::KeyEvent::RELEASE) { + let _ = obj.console().keyboard.release(*qnum as u32).await; + } })); } })); @@ -209,11 +205,11 @@ mod imp { }) ); - console.mouse.connect_is_absolute_changed(clone!(@strong widget => @default-panic, move |v| { - widget.set_mouse_absolute(v.map_or(true, |v| v.try_into().unwrap_or(true))); - async move { - }.boxed() - })).await.unwrap(); + // console.mouse.connect_is_absolute_changed(clone!(@strong widget => @default-panic, move |v| { + // widget.set_mouse_absolute(v.map_or(true, |v| v.try_into().unwrap_or(true))); + // async move { + // }.boxed() + // })).await.unwrap(); loop { if let Err(e) = console.dispatch_signals().await {