mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2025-01-03 03:05:18 +00:00
Update to current git
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
8ed884fc35
commit
bbb4846380
@ -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' }
|
||||
|
@ -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"
|
||||
|
@ -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<E: EventSender<Event = AudioOutEvent>> {
|
||||
tx: E,
|
||||
err: Arc<RefCell<Option<SendError<AudioOutEvent>>>>,
|
||||
err: Arc<OnceCell<SendError<AudioOutEvent>>>,
|
||||
}
|
||||
|
||||
impl<E: EventSender<Event = AudioOutEvent>> AudioOutListener<E> {
|
||||
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<RefCell<Option<SendError<AudioOutEvent>>>> {
|
||||
pub fn err(&self) -> Arc<OnceCell<SendError<AudioOutEvent>>> {
|
||||
self.err.clone()
|
||||
}
|
||||
}
|
||||
@ -151,22 +154,24 @@ impl<E: 'static + EventSender<Event = AudioOutEvent>> AudioOutListener<E> {
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct AudioInListener<E: EventSender<Event = AudioInEvent>> {
|
||||
tx: E,
|
||||
err: Arc<RefCell<Option<SendError<AudioInEvent>>>>,
|
||||
err: Arc<OnceCell<SendError<AudioInEvent>>>,
|
||||
}
|
||||
|
||||
impl<E: EventSender<Event = AudioInEvent>> AudioInListener<E> {
|
||||
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<RefCell<Option<SendError<AudioInEvent>>>> {
|
||||
pub fn err(&self) -> Arc<OnceCell<SendError<AudioInEvent>>> {
|
||||
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;
|
||||
}
|
||||
|
@ -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<Self> {
|
||||
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;
|
||||
}
|
||||
|
@ -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<E: EventSender<Event = ConsoleEvent>> {
|
||||
tx: E,
|
||||
wait_rx: Receiver<()>,
|
||||
err: Arc<RefCell<Option<SendError<ConsoleEvent>>>>,
|
||||
err: Arc<OnceCell<SendError<ConsoleEvent>>>,
|
||||
}
|
||||
|
||||
#[dbus_interface(name = "org.qemu.Display1.Listener")]
|
||||
@ -186,13 +186,16 @@ impl<E: 'static + EventSender<Event = ConsoleEvent>> ConsoleListener<E> {
|
||||
|
||||
impl<E: EventSender<Event = ConsoleEvent>> ConsoleListener<E> {
|
||||
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<E: EventSender<Event = ConsoleEvent>> ConsoleListener<E> {
|
||||
self.wait_rx.recv()
|
||||
}
|
||||
|
||||
pub fn err(&self) -> Arc<RefCell<Option<SendError<ConsoleEvent>>>> {
|
||||
pub fn err(&self) -> Arc<OnceCell<SendError<ConsoleEvent>>> {
|
||||
self.err.clone()
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user