cursor: simplify trait by removing barely utilized lifetimes

This commit is contained in:
Victor Brekenfeld 2020-04-19 01:26:09 +02:00
parent 8ba33f2473
commit cde06eb99a
4 changed files with 39 additions and 56 deletions

View File

@ -62,25 +62,22 @@ where
}
}
impl<'a, N> CursorBackend<'a> for EglSurface<N>
impl<N> CursorBackend for EglSurface<N>
where
N: NativeSurface + Surface + CursorBackend<'a>,
N: NativeSurface + Surface + CursorBackend,
{
type CursorFormat = <N as CursorBackend<'a>>::CursorFormat;
type Error = <N as CursorBackend<'a>>::Error;
type CursorFormat = <N as CursorBackend>::CursorFormat;
type Error = <N as CursorBackend>::Error;
fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), Self::Error> {
self.surface.set_cursor_position(x, y)
}
fn set_cursor_representation<'b>(
&'b self,
buffer: Self::CursorFormat,
fn set_cursor_representation(
&self,
buffer: &Self::CursorFormat,
hotspot: (u32, u32),
) -> ::std::result::Result<(), Self::Error>
where
'a: 'b,
{
) -> ::std::result::Result<(), Self::Error> {
self.surface.set_cursor_representation(buffer, hotspot)
}
}

View File

@ -197,22 +197,19 @@ where
// But for now got to do this:
#[cfg(feature = "backend_drm_legacy")]
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurfaceInternal<LegacyDrmDevice<A>> {
type CursorFormat = &'a ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = Error<<<LegacyDrmDevice<A> as Device>::Surface as Surface>::Error>;
impl<A: AsRawFd + 'static> CursorBackend for GbmSurfaceInternal<LegacyDrmDevice<A>> {
type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = Error<<<D as Device>::Surface as CursorBackend>::Error>;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> {
self.crtc.set_cursor_position(x, y).map_err(Error::Underlying)
}
fn set_cursor_representation<'b>(
&'b self,
fn set_cursor_representation(
&self,
buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>,
hotspot: (u32, u32),
) -> Result<(), Self::Error>
where
'a: 'b,
{
) -> Result<(), Self::Error> {
let (w, h) = buffer.dimensions();
debug!(self.logger, "Importing cursor");
@ -350,22 +347,19 @@ impl<D: RawDevice + 'static> Surface for GbmSurface<D> {
}
#[cfg(feature = "backend_drm_legacy")]
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for GbmSurface<LegacyDrmDevice<A>> {
type CursorFormat = &'a ImageBuffer<Rgba<u8>, Vec<u8>>;
impl<A: AsRawFd + 'static> CursorBackend for GbmSurface<LegacyDrmDevice<A>> {
type CursorFormat = ImageBuffer<Rgba<u8>, Vec<u8>>;
type Error = <Self as Surface>::Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Self::Error> {
self.0.set_cursor_position(x, y)
}
fn set_cursor_representation<'b>(
&'b self,
fn set_cursor_representation(
&self,
buffer: &ImageBuffer<Rgba<u8>, Vec<u8>>,
hotspot: (u32, u32),
) -> Result<(), Self::Error>
where
'a: 'b,
{
) -> Result<(), Self::Error> {
self.0.set_cursor_representation(buffer, hotspot)
}
}

View File

@ -41,8 +41,8 @@ impl<A: AsRawFd + 'static> AsRawFd for LegacyDrmSurfaceInternal<A> {
impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurfaceInternal<A> {}
impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurfaceInternal<A> {}
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal<A> {
type CursorFormat = &'a dyn Buffer;
impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurfaceInternal<A> {
type CursorFormat = dyn Buffer;
type Error = Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> {
@ -56,14 +56,11 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal<A>
})
}
fn set_cursor_representation<'b>(
&'b self,
buffer: Self::CursorFormat,
fn set_cursor_representation(
&self,
buffer: &Self::CursorFormat,
hotspot: (u32, u32),
) -> Result<(), Error>
where
'a: 'b,
{
) -> Result<(), Error> {
trace!(self.logger, "Setting the new imported cursor");
if self
@ -291,22 +288,19 @@ impl<A: AsRawFd + 'static> AsRawFd for LegacyDrmSurface<A> {
impl<A: AsRawFd + 'static> BasicDevice for LegacyDrmSurface<A> {}
impl<A: AsRawFd + 'static> ControlDevice for LegacyDrmSurface<A> {}
impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurface<A> {
type CursorFormat = &'a dyn Buffer;
impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurface<A> {
type CursorFormat = dyn Buffer;
type Error = Error;
fn set_cursor_position(&self, x: u32, y: u32) -> Result<(), Error> {
self.0.set_cursor_position(x, y)
}
fn set_cursor_representation<'b>(
&'b self,
buffer: Self::CursorFormat,
fn set_cursor_representation(
&self,
buffer: &Self::CursorFormat,
hotspot: (u32, u32),
) -> Result<(), Error>
where
'a: 'b,
{
) -> Result<(), Error> {
self.0.set_cursor_representation(buffer, hotspot)
}
}

View File

@ -4,18 +4,18 @@
/// where possible. This may however be quite restrictive in terms of supported formats.
///
/// For those reasons you may always choose to render your cursor(s) (partially) in software instead.
pub trait CursorBackend<'a> {
pub trait CursorBackend {
/// Format representing the image drawn for the cursor.
type CursorFormat: 'a;
type CursorFormat: ?Sized;
/// Error the underlying backend throws if operations fail
type Error;
type Error: 'static;
/// Sets the cursor position and therefore updates the drawn cursors position.
/// Useful as well for e.g. pointer wrapping.
///
/// Not guaranteed to be supported on every backend. The result usually
/// depends on the backend, the cursor might be "owned" by another more priviledged
/// depends on the backend, the cursor might be "owned" by another more privileged
/// compositor (running nested).
///
/// In these cases setting the position is actually not required, as movement is done
@ -29,11 +29,9 @@ pub trait CursorBackend<'a> {
/// The format is entirely dictated by the concrete implementation and might range
/// from raw image buffers over a fixed list of possible cursor types to simply the
/// void type () to represent no possible customization of the cursor itself.
fn set_cursor_representation<'b>(
&'b self,
cursor: Self::CursorFormat,
fn set_cursor_representation(
&self,
cursor: &Self::CursorFormat,
hotspot: (u32, u32),
) -> Result<(), Self::Error>
where
'a: 'b;
) -> Result<(), Self::Error>;
}