Skip to content

Commit

Permalink
Reimplement cursor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed May 12, 2019
1 parent c6ca5e0 commit 3ceabdb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,50 @@ pub trait Device: super::Device {
let _info = drm_ffi::gem::close(self.as_raw_fd(), handle.0.get())?;
Ok(())
}

/// Sets a hardware-cursor on the given crtc with the image of a given buffer
///
/// A buffer argument of `None` will clear the cursor.
fn set_cursor<B>(&self, crtc: crtc::Handle, buffer: Option<&B>) -> Result<(), SystemError>
where
B: buffer::Buffer + 'static,
{
let (id, w, h) = buffer
.map(|buf| {
let (w, h) = buf.size();
(buf.handle().0.get(), w, h)
})
.unwrap_or((0, 0, 0));
drm_ffi::mode::set_cursor(self.as_raw_fd(), crtc.as_ref().get(), id, w, h)?;

Ok(())
}

/// Sets a hardware-cursor on the given crtc with the image of a given buffer
/// and a hotspot marking the click point of the cursor.
///
/// A buffer argument of `None` will clear the cursor.
fn set_cursor2<B>(&self, crtc: crtc::Handle, buffer: Option<&B>, hotspot: (i32, i32)) -> Result<(), SystemError>
where
B: buffer::Buffer + 'static,
{
let (id, w, h) = buffer
.map(|buf| {
let (w, h) = buf.size();
(buf.handle().0.get(), w, h)
})
.unwrap_or((0, 0, 0));
drm_ffi::mode::set_cursor2(self.as_raw_fd(), crtc.as_ref().get(), id, w, h, hotspot.0, hotspot.1)?;

Ok(())
}

/// Moves a set cursor on a given crtc
fn move_cursor(&self, crtc: crtc::Handle, pos: (i32, i32)) -> Result<(), SystemError> {
drm_ffi::mode::move_cursor(self.as_raw_fd(), crtc.as_ref().get(), pos.0, pos.1)?;

Ok(())
}
}

/// The set of [ResourceHandles](ResourceHandle.t.html) that a
Expand Down

0 comments on commit 3ceabdb

Please sign in to comment.