cursor: allow cursor clearing on CursorBackend
This commit is contained in:
parent
bf011e8071
commit
51b5b39b75
|
@ -646,6 +646,15 @@ impl<A: AsRawFd + 'static> CursorBackend for AtomicDrmSurfaceInternal<A> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
let mut cursor = self.cursor.lock().unwrap();
|
||||
if let Some(fb) = cursor.framebuffer.take() {
|
||||
let _ = self.destroy_framebuffer(fb);
|
||||
}
|
||||
|
||||
self.clear_plane(self.planes.cursor)
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> AtomicDrmSurfaceInternal<A> {
|
||||
|
@ -1022,6 +1031,10 @@ impl<A: AsRawFd + 'static> CursorBackend for AtomicDrmSurface<A> {
|
|||
) -> Result<(), Error> {
|
||||
self.0.set_cursor_representation(buffer, hotspot)
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.0.clear_cursor_representation()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> Surface for AtomicDrmSurface<A> {
|
||||
|
|
|
@ -552,6 +552,7 @@ where
|
|||
|
||||
fallback_surface_err_impl!(set_cursor_position, &Self, Result<(), EitherError<E3, E4>>, x: u32, y: u32);
|
||||
fallback_surface_err_impl!(set_cursor_representation, &Self, Result<(), EitherError<E3, E4>>, buffer: &Self::CursorFormat, hotspot: (u32, u32));
|
||||
fallback_surface_err_impl!(clear_cursor_representation, &Self, Result<(), EitherError<E3, E4>>,);
|
||||
}
|
||||
|
||||
#[cfg(feature = "renderer_gl")]
|
||||
|
|
|
@ -92,6 +92,10 @@ where
|
|||
) -> ::std::result::Result<(), Self::Error> {
|
||||
self.0.surface.set_cursor_representation(buffer, hotspot)
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.0.surface.clear_cursor_representation()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "renderer_gl")]
|
||||
|
|
|
@ -190,6 +190,17 @@ impl<S: RawSurface + 'static> CursorBackend for EglStreamSurfaceInternal<S> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.crtc.set_cursor(self.crtc.crtc(), Option::<&DumbBuffer>::None)
|
||||
.compat()
|
||||
.map_err(|source| DrmError::Access {
|
||||
errmsg: "Failed to clear cursor",
|
||||
dev: self.crtc.dev_path(),
|
||||
source,
|
||||
})
|
||||
.map_err(Error::Underlying)
|
||||
}
|
||||
}
|
||||
|
||||
/// egl stream surface for rendering
|
||||
|
@ -565,6 +576,10 @@ impl<S: RawSurface + 'static> CursorBackend for EglStreamSurface<S> {
|
|||
) -> Result<(), Self::Error> {
|
||||
self.0.set_cursor_representation(buffer, hotspot)
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.0.clear_cursor_representation()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -305,6 +305,22 @@ where
|
|||
*self.cursor.lock().unwrap() = (cursor, hotspot);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
*self.cursor.lock().unwrap() = (self.dev.lock()
|
||||
.unwrap()
|
||||
.create_buffer_object(
|
||||
1,
|
||||
1,
|
||||
GbmFormat::ARGB8888,
|
||||
BufferObjectFlags::CURSOR | BufferObjectFlags::WRITE,
|
||||
)
|
||||
.map_err(Error::BufferCreationFailed)?,
|
||||
(0, 0)
|
||||
);
|
||||
self.crtc.clear_cursor_representation()
|
||||
.map_err(Error::Underlying)
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: RawSurface + 'static> Drop for GbmSurfaceInternal<S> {
|
||||
|
@ -415,6 +431,10 @@ where
|
|||
) -> Result<(), Self::Error> {
|
||||
self.0.set_cursor_representation(buffer, hotspot)
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.0.clear_cursor_representation()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -87,6 +87,16 @@ impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurfaceInternal<A> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Error> {
|
||||
self.set_cursor(self.crtc, Option::<&DumbBuffer>::None)
|
||||
.compat()
|
||||
.map_err(|source| Error::Access {
|
||||
errmsg: "Failed to set cursor",
|
||||
dev: self.dev_path(),
|
||||
source,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> Surface for LegacyDrmSurfaceInternal<A> {
|
||||
|
@ -498,6 +508,10 @@ impl<A: AsRawFd + 'static> CursorBackend for LegacyDrmSurface<A> {
|
|||
) -> Result<(), Error> {
|
||||
self.0.set_cursor_representation(buffer, hotspot)
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error> {
|
||||
self.0.clear_cursor_representation()
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: AsRawFd + 'static> Surface for LegacyDrmSurface<A> {
|
||||
|
|
|
@ -34,4 +34,7 @@ pub trait CursorBackend {
|
|||
cursor: &Self::CursorFormat,
|
||||
hotspot: (u32, u32),
|
||||
) -> Result<(), Self::Error>;
|
||||
|
||||
/// Clear the current cursor image drawn on the [`CursorBackend`].
|
||||
fn clear_cursor_representation(&self) -> Result<(), Self::Error>;
|
||||
}
|
||||
|
|
|
@ -270,6 +270,12 @@ impl CursorBackend for WinitGraphicsBackend {
|
|||
// Cannot log this one, as `CursorFormat` is not `Debug` and should not be
|
||||
debug!(self.logger, "Changing cursor representation");
|
||||
self.window.window().set_cursor_icon(*cursor);
|
||||
self.window.window().set_cursor_visible(true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn clear_cursor_representation(&self) -> ::std::result::Result<(), ()> {
|
||||
self.window.window().set_cursor_visible(false);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue