diff --git a/src/backend/glutin.rs b/src/backend/glutin.rs index 5a289e5..a79bd93 100644 --- a/src/backend/glutin.rs +++ b/src/backend/glutin.rs @@ -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 diff --git a/src/backend/graphics/mod.rs b/src/backend/graphics/mod.rs index 75b2ee6..9d1cdde 100644 --- a/src/backend/graphics/mod.rs +++ b/src/backend/graphics/mod.rs @@ -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; diff --git a/src/backend/graphics/opengl.rs b/src/backend/graphics/opengl.rs index a03f93b..d0457aa 100644 --- a/src/backend/graphics/opengl.rs +++ b/src/backend/graphics/opengl.rs @@ -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>; diff --git a/src/backend/graphics/software.rs b/src/backend/graphics/software.rs index 278885a..7e9d474 100644 --- a/src/backend/graphics/software.rs +++ b/src/backend/graphics/software.rs @@ -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 { +pub trait CpuGraphicsBackend: GraphicsBackend { /// Render a given buffer of a given format at a specified place in the framebuffer /// /// # Error diff --git a/src/backend/input.rs b/src/backend/input.rs index 671b2c5..6251682 100644 --- a/src/backend/input.rs +++ b/src/backend/input.rs @@ -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`. diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 7609d81..f65097e 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -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 {