From 5f4810d994b39d24ae2c970c2e6f478c08ec6ef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Wed, 25 Sep 2024 17:20:18 +0400 Subject: [PATCH] qemu-display: add Listener.Unix.Map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marc-André Lureau --- qemu-display/src/console.rs | 10 ++----- qemu-display/src/console_listener.rs | 42 +++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/qemu-display/src/console.rs b/qemu-display/src/console.rs index 214fc5a..4d7ee3a 100644 --- a/qemu-display/src/console.rs +++ b/qemu-display/src/console.rs @@ -10,14 +10,11 @@ use zbus::zvariant::Fd; use zbus::{zvariant::ObjectPath, Connection}; use crate::{ - util, ConsoleListener, ConsoleListenerHandler, KeyboardProxy, MouseProxy, MultiTouchProxy, - Result, + util, ConsoleListener, ConsoleListenerHandler, ConsoleListenerMap, ConsoleListenerMapHandler, + KeyboardProxy, MouseProxy, MultiTouchProxy, Result, }; #[cfg(windows)] -use crate::{ - ConsoleListenerD3d11, ConsoleListenerD3d11Handler, ConsoleListenerMap, - ConsoleListenerMapHandler, -}; +use crate::{ConsoleListenerD3d11, ConsoleListenerD3d11Handler}; #[zbus::proxy(default_service = "org.qemu", interface = "org.qemu.Display1.Console")] pub trait Console { @@ -122,7 +119,6 @@ impl Console { Ok(()) } - #[cfg(windows)] pub async fn set_map_listener(&self, handler: H) -> Result { if let Some(l) = &*self.listener.write().unwrap() { return l diff --git a/qemu-display/src/console_listener.rs b/qemu-display/src/console_listener.rs index b305791..a8cbf2f 100644 --- a/qemu-display/src/console_listener.rs +++ b/qemu-display/src/console_listener.rs @@ -1,9 +1,12 @@ #[cfg(windows)] use crate::win32::Fd; use derivative::Derivative; -use std::ops::Drop; #[cfg(unix)] use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; +use std::{ + ops::Drop, + os::fd::{AsFd, OwnedFd}, +}; #[cfg(unix)] use zbus::zvariant::Fd; @@ -33,6 +36,9 @@ pub struct Update { #[derive(Debug)] pub struct ScanoutMap { + #[cfg(unix)] + pub fd: OwnedFd, + #[cfg(windows)] pub handle: u64, pub offset: u32, pub width: u32, @@ -309,7 +315,6 @@ impl Drop for ConsoleListener { } } -#[cfg(windows)] #[async_trait::async_trait] pub trait ConsoleListenerMapHandler: 'static + Send + Sync { async fn scanout_map(&mut self, scanout: ScanoutMap); @@ -317,12 +322,42 @@ pub trait ConsoleListenerMapHandler: 'static + Send + Sync { async fn update_map(&mut self, update: UpdateMap); } -#[cfg(windows)] #[derive(Debug)] pub(crate) struct ConsoleListenerMap { handler: H, } +#[cfg(unix)] +#[zbus::interface(name = "org.qemu.Display1.Listener.Unix.Map")] +impl ConsoleListenerMap { + async fn scanout_map( + &mut self, + fd: Fd<'_>, + offset: u32, + width: u32, + height: u32, + stride: u32, + format: u32, + ) -> zbus::fdo::Result<()> { + let map = ScanoutMap { + fd: fd.as_fd().try_clone_to_owned().unwrap(), + offset, + width, + height, + stride, + format, + }; + self.handler.scanout_map(map).await; + Ok(()) + } + + async fn update_map(&mut self, x: i32, y: i32, w: i32, h: i32) -> zbus::fdo::Result<()> { + let up = UpdateMap { x, y, w, h }; + self.handler.update_map(up).await; + Ok(()) + } +} + #[cfg(windows)] #[zbus::interface(name = "org.qemu.Display1.Listener.Win32.Map")] impl ConsoleListenerMap { @@ -354,7 +389,6 @@ impl ConsoleListenerMap { } } -#[cfg(windows)] impl ConsoleListenerMap { pub(crate) fn new(handler: H) -> Self { Self { handler }