Move set_cursor_position to the graphics backend
This commit is contained in:
parent
f95faba80f
commit
109f4035e8
|
@ -2,6 +2,7 @@
|
|||
|
||||
|
||||
use backend::{SeatInternal, TouchSlotInternal};
|
||||
use backend::graphics::GraphicsBackend;
|
||||
use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError};
|
||||
use backend::input::{Axis, AxisSource, InputBackend, InputHandler, KeyState, MouseButton, MouseButtonState,
|
||||
Seat, SeatCapabilities, TouchEvent, TouchSlot};
|
||||
|
@ -79,6 +80,13 @@ impl GlutinHeadlessRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
impl GraphicsBackend for GlutinHeadlessRenderer {
|
||||
fn set_cursor_position(&mut self, _x: u32, _y: u32) -> Result<(), ()> {
|
||||
//FIXME: Maybe save position? Is it of any use?
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl OpenglGraphicsBackend for GlutinHeadlessRenderer {
|
||||
#[inline]
|
||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
||||
|
@ -130,6 +138,17 @@ impl GlutinWindowedRenderer {
|
|||
}
|
||||
}
|
||||
|
||||
impl GraphicsBackend for GlutinWindowedRenderer {
|
||||
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> {
|
||||
if let Some((win_x, win_y)) = self.window.get_position() {
|
||||
self.window
|
||||
.set_cursor_position(win_x + x as i32, win_y + y as i32)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OpenglGraphicsBackend for GlutinWindowedRenderer {
|
||||
#[inline]
|
||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
||||
|
@ -233,15 +252,6 @@ impl InputBackend for GlutinInputBackend {
|
|||
&mut self.input_config
|
||||
}
|
||||
|
||||
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()> {
|
||||
if let Some((win_x, win_y)) = self.window.get_position() {
|
||||
self.window
|
||||
.set_cursor_position(win_x + x as i32, win_y + y as i32)
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Processes new events of the underlying event loop to drive the set `InputHandler`.
|
||||
///
|
||||
/// You need to periodically call this function to keep the underlying event loop and
|
||||
|
|
|
@ -2,5 +2,22 @@
|
|||
//!
|
||||
//! Note: Not every api may be supported by every backend
|
||||
|
||||
/// General functions any graphics backend should support independently from it's rendering
|
||||
/// techique.
|
||||
pub trait GraphicsBackend {
|
||||
/// Sets the cursor position and therefor 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
|
||||
/// compositor (running nested).
|
||||
///
|
||||
/// In these cases setting the position is actually not required, as movement is done
|
||||
/// by the higher compositor and not by the backend. It is still good practice to update
|
||||
/// the position after every recieved event, but don't rely on pointer wrapping working.
|
||||
///
|
||||
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()>;
|
||||
}
|
||||
|
||||
pub mod software;
|
||||
pub mod opengl;
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use nix::c_void;
|
||||
|
||||
use super::GraphicsBackend;
|
||||
|
||||
/// Error that can happen when swapping buffers.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SwapBuffersError {
|
||||
|
@ -61,7 +63,7 @@ pub struct PixelFormat {
|
|||
|
||||
/// Trait that describes objects that have an OpenGl context
|
||||
/// and can be used to render upon
|
||||
pub trait OpenglGraphicsBackend {
|
||||
pub trait OpenglGraphicsBackend: GraphicsBackend {
|
||||
/// Swaps buffers at the end of a frame.
|
||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
|
||||
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
use std::error::Error;
|
||||
use wayland_server::protocol::wl_shm::Format;
|
||||
|
||||
use super::GraphicsBackend;
|
||||
|
||||
/// Trait that describes objects providing a software rendering implementation
|
||||
pub trait CpuGraphicsBackend<E: Error> {
|
||||
pub trait CpuGraphicsBackend<E: Error>: GraphicsBackend {
|
||||
/// Render a given buffer of a given format at a specified place in the framebuffer
|
||||
///
|
||||
/// # Error
|
||||
|
|
|
@ -218,13 +218,6 @@ pub trait InputBackend: Sized {
|
|||
|
||||
/// Processes new events of the underlying backend and drives the `InputHandler`.
|
||||
fn dispatch_new_events(&mut self) -> Result<(), Self::EventError>;
|
||||
|
||||
/// Sets the cursor position, useful for e.g. pointer wrapping.
|
||||
///
|
||||
/// Not guaranteed to be supported on every backend. The result usually
|
||||
/// depends on the capability of the backend, but may also fail for certain
|
||||
/// specific actions. See the backends documentation.
|
||||
fn set_cursor_position(&mut self, x: u32, y: u32) -> Result<(), ()>;
|
||||
}
|
||||
|
||||
/// Implement to receive input events from any `InputBackend`.
|
||||
|
|
|
@ -80,13 +80,6 @@ impl InputBackend for LibinputInputBackend {
|
|||
&mut self.devices
|
||||
}
|
||||
|
||||
fn set_cursor_position(&mut self, _x: u32, _y: u32) -> Result<(), ()> {
|
||||
// FIXME later.
|
||||
// This will be doable with the hardware cursor api and probably some more cases
|
||||
warn!(self.logger, "Setting the cursor position is currently unsupported by the libinput backend");
|
||||
Err(())
|
||||
}
|
||||
|
||||
fn dispatch_new_events(&mut self) -> Result<(), IoError> {
|
||||
self.context.dispatch()?;
|
||||
for event in &mut self.context {
|
||||
|
|
Loading…
Reference in New Issue