Fix formatting
This commit is contained in:
parent
369c8a980e
commit
ae375624ac
|
@ -1,9 +1,9 @@
|
||||||
extern crate wayland_server;
|
extern crate wayland_server;
|
||||||
extern crate smithay;
|
extern crate smithay;
|
||||||
|
|
||||||
use smithay::shm::ShmGlobal;
|
|
||||||
use smithay::backend::glutin;
|
use smithay::backend::glutin;
|
||||||
use smithay::backend::input::InputBackend;
|
use smithay::backend::input::InputBackend;
|
||||||
|
use smithay::shm::ShmGlobal;
|
||||||
use wayland_server::protocol::wl_shm;
|
use wayland_server::protocol::wl_shm;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -11,13 +11,11 @@ fn main() {
|
||||||
|
|
||||||
// Insert the ShmGlobal as a handler to your event loop
|
// Insert the ShmGlobal as a handler to your event loop
|
||||||
// Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported.
|
// Here, we specify tha the standard Argb8888 and Xrgb8888 is the only supported.
|
||||||
let handler_id = event_loop.add_handler_with_init(ShmGlobal::new(
|
let handler_id =
|
||||||
vec![],
|
event_loop.add_handler_with_init(ShmGlobal::new(vec![], None /* we don't provide a logger here */));
|
||||||
None // we don't provide a logger here
|
|
||||||
));
|
|
||||||
|
|
||||||
// Register this handler to advertise a wl_shm global of version 1
|
// Register this handler to advertise a wl_shm global of version 1
|
||||||
let shm_global = event_loop.register_global::<wl_shm::WlShm,ShmGlobal>(handler_id, 1);
|
let shm_global = event_loop.register_global::<wl_shm::WlShm, ShmGlobal>(handler_id, 1);
|
||||||
|
|
||||||
// Retrieve the shm token for later use to access the buffers
|
// Retrieve the shm token for later use to access the buffers
|
||||||
let shm_token = {
|
let shm_token = {
|
||||||
|
@ -28,9 +26,9 @@ fn main() {
|
||||||
// Initialize a simple backend for testing
|
// Initialize a simple backend for testing
|
||||||
let (mut renderer, mut input) = glutin::init_windowed().unwrap();
|
let (mut renderer, mut input) = glutin::init_windowed().unwrap();
|
||||||
|
|
||||||
//TODO render stuff
|
// TODO render stuff
|
||||||
|
|
||||||
//TODO put input handling on the event loop
|
// TODO put input handling on the event loop
|
||||||
input.dispatch_new_events().unwrap();
|
input.dispatch_new_events().unwrap();
|
||||||
|
|
||||||
event_loop.run().unwrap();
|
event_loop.run().unwrap();
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use glium::backend::Backend;
|
|
||||||
|
|
||||||
|
use backend::graphics::opengl::{OpenglGraphicsBackend, SwapBuffersError};
|
||||||
use glium::SwapBuffersError as GliumSwapBuffersError;
|
use glium::SwapBuffersError as GliumSwapBuffersError;
|
||||||
|
use glium::backend::Backend;
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
|
|
||||||
use ::backend::graphics::opengl::{OpenglGraphicsBackend, SwapBuffersError};
|
impl From<SwapBuffersError> for GliumSwapBuffersError {
|
||||||
|
|
||||||
impl From<SwapBuffersError> for GliumSwapBuffersError
|
|
||||||
{
|
|
||||||
fn from(error: SwapBuffersError) -> Self {
|
fn from(error: SwapBuffersError) -> Self {
|
||||||
match error {
|
match error {
|
||||||
SwapBuffersError::ContextLost => GliumSwapBuffersError::ContextLost,
|
SwapBuffersError::ContextLost => GliumSwapBuffersError::ContextLost,
|
||||||
|
@ -17,27 +17,22 @@ impl From<SwapBuffersError> for GliumSwapBuffersError
|
||||||
|
|
||||||
pub struct GliumGraphicBackend<T: OpenglGraphicsBackend>(T);
|
pub struct GliumGraphicBackend<T: OpenglGraphicsBackend>(T);
|
||||||
|
|
||||||
pub trait IntoGlium: OpenglGraphicsBackend + Sized
|
pub trait IntoGlium: OpenglGraphicsBackend + Sized {
|
||||||
{
|
|
||||||
fn into_glium(self) -> GliumGraphicBackend<Self>;
|
fn into_glium(self) -> GliumGraphicBackend<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: OpenglGraphicsBackend> IntoGlium for T
|
impl<T: OpenglGraphicsBackend> IntoGlium for T {
|
||||||
{
|
fn into_glium(self) -> GliumGraphicBackend<Self> {
|
||||||
fn into_glium(self) -> GliumGraphicBackend<Self>
|
|
||||||
{
|
|
||||||
GliumGraphicBackend(self)
|
GliumGraphicBackend(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: OpenglGraphicsBackend> Backend for GliumGraphicBackend<T>
|
unsafe impl<T: OpenglGraphicsBackend> Backend for GliumGraphicBackend<T> {
|
||||||
{
|
|
||||||
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
|
fn swap_buffers(&self) -> Result<(), GliumSwapBuffersError> {
|
||||||
self.0.swap_buffers().map_err(Into::into)
|
self.0.swap_buffers().map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void
|
unsafe fn get_proc_address(&self, symbol: &str) -> *const c_void {
|
||||||
{
|
|
||||||
self.0.get_proc_address(symbol) as *const c_void
|
self.0.get_proc_address(symbol) as *const c_void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,29 @@
|
||||||
//! Implementation of backend traits for types provided by `glutin`
|
//! Implementation of backend traits for types provided by `glutin`
|
||||||
|
|
||||||
use glutin::{ContextError, CreationError, Event, ElementState, MouseScrollDelta, Touch, TouchPhase, GlContext, HeadlessRendererBuilder, HeadlessContext, WindowBuilder, Window};
|
|
||||||
use glutin::{Api as GlutinApi, PixelFormat as GlutinPixelFormat, MouseButton as GlutinMouseButton};
|
|
||||||
use nix::c_void;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::error::Error;
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
use backend::{SeatInternal, TouchSlotInternal};
|
use backend::{SeatInternal, TouchSlotInternal};
|
||||||
use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError};
|
use backend::graphics::opengl::{Api, OpenglGraphicsBackend, PixelFormat, SwapBuffersError};
|
||||||
use backend::input::{InputBackend, InputHandler, Seat, SeatCapabilities, KeyState, MouseButton, MouseButtonState, Axis, AxisSource, TouchEvent, TouchSlot};
|
use backend::input::{Axis, AxisSource, InputBackend, InputHandler, KeyState, MouseButton, MouseButtonState,
|
||||||
|
Seat, SeatCapabilities, TouchEvent, TouchSlot};
|
||||||
|
use glutin::{Api as GlutinApi, MouseButton as GlutinMouseButton, PixelFormat as GlutinPixelFormat};
|
||||||
|
use glutin::{ContextError, CreationError, ElementState, Event, GlContext, HeadlessContext,
|
||||||
|
HeadlessRendererBuilder, MouseScrollDelta, Touch, TouchPhase, Window, WindowBuilder};
|
||||||
|
use nix::c_void;
|
||||||
|
use std::error::Error;
|
||||||
|
use std::fmt;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// Create a new `GlutinHeadlessRenderer` which implements the `OpenglRenderer` graphics
|
/// Create a new `GlutinHeadlessRenderer` which implements the `OpenglRenderer` graphics
|
||||||
/// backend trait
|
/// backend trait
|
||||||
pub fn init_headless_renderer() -> Result<GlutinHeadlessRenderer, CreationError>
|
pub fn init_headless_renderer() -> Result<GlutinHeadlessRenderer, CreationError> {
|
||||||
{
|
|
||||||
init_headless_renderer_from_builder(HeadlessRendererBuilder::new(1024, 600))
|
init_headless_renderer_from_builder(HeadlessRendererBuilder::new(1024, 600))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `GlutinHeadlessRenderer`, which implements the `OpenglRenderer` graphics
|
/// Create a new `GlutinHeadlessRenderer`, which implements the `OpenglRenderer` graphics
|
||||||
/// backend trait, with a given already configured `HeadlessRendererBuilder` for
|
/// backend trait, with a given already configured `HeadlessRendererBuilder` for
|
||||||
/// customization
|
/// customization
|
||||||
pub fn init_headless_renderer_from_builder(builder: HeadlessRendererBuilder) -> Result<GlutinHeadlessRenderer, CreationError>
|
pub fn init_headless_renderer_from_builder(builder: HeadlessRendererBuilder)
|
||||||
{
|
-> Result<GlutinHeadlessRenderer, CreationError> {
|
||||||
let (w, h) = builder.dimensions;
|
let (w, h) = builder.dimensions;
|
||||||
let context = builder.build_strict()?;
|
let context = builder.build_strict()?;
|
||||||
|
|
||||||
|
@ -31,15 +32,14 @@ pub fn init_headless_renderer_from_builder(builder: HeadlessRendererBuilder) ->
|
||||||
|
|
||||||
/// Create a new `GlutinWindowedRenderer`, which implements the `OpenglRenderer` graphics
|
/// Create a new `GlutinWindowedRenderer`, which implements the `OpenglRenderer` graphics
|
||||||
/// backend trait
|
/// backend trait
|
||||||
pub fn init_windowed_renderer() -> Result<GlutinWindowedRenderer, CreationError>
|
pub fn init_windowed_renderer() -> Result<GlutinWindowedRenderer, CreationError> {
|
||||||
{
|
|
||||||
init_windowed_renderer_from_builder(WindowBuilder::new())
|
init_windowed_renderer_from_builder(WindowBuilder::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `GlutinWindowedRenderer`, which implements the `OpenglRenderer` graphics
|
/// Create a new `GlutinWindowedRenderer`, which implements the `OpenglRenderer` graphics
|
||||||
/// backend trait, with a given already configured `WindowBuilder` for customization.
|
/// backend trait, with a given already configured `WindowBuilder` for customization.
|
||||||
pub fn init_windowed_renderer_from_builder(builder: WindowBuilder) -> Result<GlutinWindowedRenderer, CreationError>
|
pub fn init_windowed_renderer_from_builder(builder: WindowBuilder)
|
||||||
{
|
-> Result<GlutinWindowedRenderer, CreationError> {
|
||||||
let window = Rc::new(builder.build_strict()?);
|
let window = Rc::new(builder.build_strict()?);
|
||||||
Ok(GlutinWindowedRenderer::new(window))
|
Ok(GlutinWindowedRenderer::new(window))
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,7 @@ pub fn init_windowed_renderer_from_builder(builder: WindowBuilder) -> Result<Glu
|
||||||
/// Create a new `glutin` `Window`. Returns a `GlutinWindowedRenderer` implementing
|
/// Create a new `glutin` `Window`. Returns a `GlutinWindowedRenderer` implementing
|
||||||
/// the `OpenglRenderer` graphics backend trait and a `GlutinInputBackend` implementing
|
/// the `OpenglRenderer` graphics backend trait and a `GlutinInputBackend` implementing
|
||||||
/// the `InputBackend` trait.
|
/// the `InputBackend` trait.
|
||||||
pub fn init_windowed() -> Result<(GlutinWindowedRenderer, GlutinInputBackend), CreationError>
|
pub fn init_windowed() -> Result<(GlutinWindowedRenderer, GlutinInputBackend), CreationError> {
|
||||||
{
|
|
||||||
init_windowed_from_builder(WindowBuilder::new())
|
init_windowed_from_builder(WindowBuilder::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,26 +55,21 @@ pub fn init_windowed() -> Result<(GlutinWindowedRenderer, GlutinInputBackend), C
|
||||||
/// customization. Returns a `GlutinWindowedRenderer` implementing
|
/// customization. Returns a `GlutinWindowedRenderer` implementing
|
||||||
/// the `OpenglRenderer` graphics backend trait and a `GlutinInputBackend` implementing
|
/// the `OpenglRenderer` graphics backend trait and a `GlutinInputBackend` implementing
|
||||||
/// the `InputBackend` trait.
|
/// the `InputBackend` trait.
|
||||||
pub fn init_windowed_from_builder(builder: WindowBuilder) -> Result<(GlutinWindowedRenderer, GlutinInputBackend), CreationError>
|
pub fn init_windowed_from_builder(builder: WindowBuilder)
|
||||||
{
|
-> Result<(GlutinWindowedRenderer, GlutinInputBackend), CreationError> {
|
||||||
let window = Rc::new(builder.build_strict()?);
|
let window = Rc::new(builder.build_strict()?);
|
||||||
Ok((
|
Ok((GlutinWindowedRenderer::new(window.clone()), GlutinInputBackend::new(window)))
|
||||||
GlutinWindowedRenderer::new(window.clone()),
|
|
||||||
GlutinInputBackend::new(window)
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Headless Opengl Context created by `glutin`. Implements the `OpenglGraphicsBackend` graphics
|
/// Headless Opengl Context created by `glutin`. Implements the `OpenglGraphicsBackend` graphics
|
||||||
/// backend trait.
|
/// backend trait.
|
||||||
pub struct GlutinHeadlessRenderer
|
pub struct GlutinHeadlessRenderer {
|
||||||
{
|
|
||||||
context: HeadlessContext,
|
context: HeadlessContext,
|
||||||
w: u32,
|
w: u32,
|
||||||
h: u32,
|
h: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlutinHeadlessRenderer
|
impl GlutinHeadlessRenderer {
|
||||||
{
|
|
||||||
fn new(context: HeadlessContext, w: u32, h: u32) -> GlutinHeadlessRenderer {
|
fn new(context: HeadlessContext, w: u32, h: u32) -> GlutinHeadlessRenderer {
|
||||||
GlutinHeadlessRenderer {
|
GlutinHeadlessRenderer {
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -85,8 +79,7 @@ impl GlutinHeadlessRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenglGraphicsBackend for GlutinHeadlessRenderer
|
impl OpenglGraphicsBackend for GlutinHeadlessRenderer {
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
||||||
match self.context.swap_buffers() {
|
match self.context.swap_buffers() {
|
||||||
|
@ -127,22 +120,17 @@ impl OpenglGraphicsBackend for GlutinHeadlessRenderer
|
||||||
|
|
||||||
/// Window with an active Opengl Context created by `glutin`. Implements the
|
/// Window with an active Opengl Context created by `glutin`. Implements the
|
||||||
/// `OpenglGraphicsBackend` graphics backend trait.
|
/// `OpenglGraphicsBackend` graphics backend trait.
|
||||||
pub struct GlutinWindowedRenderer
|
pub struct GlutinWindowedRenderer {
|
||||||
{
|
window: Rc<Window>,
|
||||||
window: Rc<Window>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlutinWindowedRenderer
|
impl GlutinWindowedRenderer {
|
||||||
{
|
|
||||||
fn new(window: Rc<Window>) -> GlutinWindowedRenderer {
|
fn new(window: Rc<Window>) -> GlutinWindowedRenderer {
|
||||||
GlutinWindowedRenderer {
|
GlutinWindowedRenderer { window: window }
|
||||||
window: window,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenglGraphicsBackend for GlutinWindowedRenderer
|
impl OpenglGraphicsBackend for GlutinWindowedRenderer {
|
||||||
{
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
|
||||||
match self.window.swap_buffers() {
|
match self.window.swap_buffers() {
|
||||||
|
@ -185,28 +173,23 @@ impl OpenglGraphicsBackend for GlutinWindowedRenderer
|
||||||
|
|
||||||
/// Errors that may happen when driving the event loop of `GlutinInputBackend`
|
/// Errors that may happen when driving the event loop of `GlutinInputBackend`
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum GlutinInputError
|
pub enum GlutinInputError {
|
||||||
{
|
|
||||||
/// The underlying `glutin` `Window` was closed. No further events can be processed.
|
/// The underlying `glutin` `Window` was closed. No further events can be processed.
|
||||||
///
|
///
|
||||||
/// See `GlutinInputBackend::process_new_events`.
|
/// See `GlutinInputBackend::process_new_events`.
|
||||||
WindowClosed
|
WindowClosed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for GlutinInputError
|
impl Error for GlutinInputError {
|
||||||
{
|
fn description(&self) -> &str {
|
||||||
fn description(&self) -> &str
|
|
||||||
{
|
|
||||||
match *self {
|
match *self {
|
||||||
GlutinInputError::WindowClosed => "Glutin Window was closed",
|
GlutinInputError::WindowClosed => "Glutin Window was closed",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for GlutinInputError
|
impl fmt::Display for GlutinInputError {
|
||||||
{
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
|
|
||||||
{
|
|
||||||
write!(f, "{}", self.description())
|
write!(f, "{}", self.description())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,8 +197,7 @@ impl fmt::Display for GlutinInputError
|
||||||
/// Abstracted event loop of a `glutin` `Window` implementing the `InputBackend` trait
|
/// Abstracted event loop of a `glutin` `Window` implementing the `InputBackend` trait
|
||||||
///
|
///
|
||||||
/// You need to call `process_new_events` periodically to receive any events.
|
/// You need to call `process_new_events` periodically to receive any events.
|
||||||
pub struct GlutinInputBackend
|
pub struct GlutinInputBackend {
|
||||||
{
|
|
||||||
window: Rc<Window>,
|
window: Rc<Window>,
|
||||||
time_counter: u32,
|
time_counter: u32,
|
||||||
seat: Seat,
|
seat: Seat,
|
||||||
|
@ -223,8 +205,7 @@ pub struct GlutinInputBackend
|
||||||
handler: Option<Box<InputHandler<GlutinInputBackend> + 'static>>,
|
handler: Option<Box<InputHandler<GlutinInputBackend> + 'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputBackend for GlutinInputBackend
|
impl InputBackend for GlutinInputBackend {
|
||||||
{
|
|
||||||
type InputConfig = ();
|
type InputConfig = ();
|
||||||
type EventError = GlutinInputError;
|
type EventError = GlutinInputError;
|
||||||
|
|
||||||
|
@ -236,8 +217,7 @@ impl InputBackend for GlutinInputBackend
|
||||||
self.handler = Some(Box::new(handler));
|
self.handler = Some(Box::new(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>>
|
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> {
|
||||||
{
|
|
||||||
self.handler.as_mut().map(|handler| handler as &mut InputHandler<Self>)
|
self.handler.as_mut().map(|handler| handler as &mut InputHandler<Self>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,42 +251,96 @@ impl InputBackend for GlutinInputBackend
|
||||||
///
|
///
|
||||||
/// The linked `GlutinWindowedRenderer` will error with a lost Context and should
|
/// The linked `GlutinWindowedRenderer` will error with a lost Context and should
|
||||||
/// not be used anymore as well.
|
/// not be used anymore as well.
|
||||||
fn dispatch_new_events(&mut self) -> Result<(), GlutinInputError>
|
fn dispatch_new_events(&mut self) -> Result<(), GlutinInputError> {
|
||||||
{
|
for event in self.window.poll_events() {
|
||||||
for event in self.window.poll_events()
|
|
||||||
{
|
|
||||||
if let Some(ref mut handler) = self.handler {
|
if let Some(ref mut handler) = self.handler {
|
||||||
match event {
|
match event {
|
||||||
Event::KeyboardInput(state, key_code, _) => handler.on_keyboard_key(&self.seat, self.time_counter, key_code as u32, state.into(), 1),
|
Event::KeyboardInput(state, key_code, _) => {
|
||||||
Event::MouseMoved(x, y) => handler.on_pointer_move(&self.seat, self.time_counter, (x as u32, y as u32)),
|
handler.on_keyboard_key(&self.seat,
|
||||||
Event::MouseWheel(delta, _) => match delta {
|
self.time_counter,
|
||||||
|
key_code as u32,
|
||||||
|
state.into(),
|
||||||
|
1)
|
||||||
|
}
|
||||||
|
Event::MouseMoved(x, y) => {
|
||||||
|
handler.on_pointer_move(&self.seat, self.time_counter, (x as u32, y as u32))
|
||||||
|
}
|
||||||
|
Event::MouseWheel(delta, _) => {
|
||||||
|
match delta {
|
||||||
MouseScrollDelta::LineDelta(x, y) => {
|
MouseScrollDelta::LineDelta(x, y) => {
|
||||||
if x != 0.0 {
|
if x != 0.0 {
|
||||||
handler.on_pointer_scroll(&self.seat, self.time_counter, Axis::Horizontal, AxisSource::Wheel, x as f64);
|
handler.on_pointer_scroll(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
Axis::Horizontal,
|
||||||
|
AxisSource::Wheel,
|
||||||
|
x as f64);
|
||||||
}
|
}
|
||||||
if y != 0.0 {
|
if y != 0.0 {
|
||||||
handler.on_pointer_scroll(&self.seat, self.time_counter, Axis::Vertical, AxisSource::Wheel, y as f64);
|
handler.on_pointer_scroll(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
Axis::Vertical,
|
||||||
|
AxisSource::Wheel,
|
||||||
|
y as f64);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
MouseScrollDelta::PixelDelta(x, y) => {
|
MouseScrollDelta::PixelDelta(x, y) => {
|
||||||
if x != 0.0 {
|
if x != 0.0 {
|
||||||
handler.on_pointer_scroll(&self.seat, self.time_counter, Axis::Vertical, AxisSource::Continous, x as f64);
|
handler.on_pointer_scroll(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
Axis::Vertical,
|
||||||
|
AxisSource::Continous,
|
||||||
|
x as f64);
|
||||||
}
|
}
|
||||||
if y != 0.0 {
|
if y != 0.0 {
|
||||||
handler.on_pointer_scroll(&self.seat, self.time_counter, Axis::Horizontal, AxisSource::Continous, y as f64);
|
handler.on_pointer_scroll(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
Axis::Horizontal,
|
||||||
|
AxisSource::Continous,
|
||||||
|
y as f64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Event::MouseInput(state, button) => {
|
||||||
|
handler.on_pointer_button(&self.seat, self.time_counter, button.into(), state.into())
|
||||||
|
}
|
||||||
|
Event::Touch(Touch { phase: TouchPhase::Started, location: (x, y), id }) => {
|
||||||
|
handler.on_touch(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
TouchEvent::Down {
|
||||||
|
slot: Some(TouchSlot::new(id as u32)),
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Event::Touch(Touch { phase: TouchPhase::Moved, location: (x, y), id }) => {
|
||||||
|
handler.on_touch(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
TouchEvent::Motion {
|
||||||
|
slot: Some(TouchSlot::new(id as u32)),
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
|
||||||
},
|
|
||||||
Event::MouseInput(state, button) => handler.on_pointer_button(&self.seat, self.time_counter, button.into(), state.into()),
|
|
||||||
Event::Touch(Touch { phase: TouchPhase::Started, location: (x, y), id}) => handler.on_touch(&self.seat, self.time_counter, TouchEvent::Down { slot: Some(TouchSlot::new(id as u32)), x: x, y: y }),
|
|
||||||
Event::Touch(Touch { phase: TouchPhase::Moved, location: (x, y), id}) => handler.on_touch(&self.seat, self.time_counter, TouchEvent::Motion { slot: Some(TouchSlot::new(id as u32)), x: x, y: y }),
|
|
||||||
Event::Touch(Touch { phase: TouchPhase::Ended, location: (x, y), id }) => {
|
Event::Touch(Touch { phase: TouchPhase::Ended, location: (x, y), id }) => {
|
||||||
handler.on_touch(&self.seat, self.time_counter, TouchEvent::Motion { slot: Some(TouchSlot::new(id as u32)), x: x, y: y });
|
handler.on_touch(&self.seat,
|
||||||
handler.on_touch(&self.seat, self.time_counter, TouchEvent::Up { slot: Some(TouchSlot::new(id as u32)) });
|
self.time_counter,
|
||||||
|
TouchEvent::Motion {
|
||||||
|
slot: Some(TouchSlot::new(id as u32)),
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
});
|
||||||
|
handler.on_touch(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
TouchEvent::Up { slot: Some(TouchSlot::new(id as u32)) });
|
||||||
|
}
|
||||||
|
Event::Touch(Touch { phase: TouchPhase::Cancelled, id, .. }) => {
|
||||||
|
handler.on_touch(&self.seat,
|
||||||
|
self.time_counter,
|
||||||
|
TouchEvent::Cancel { slot: Some(TouchSlot::new(id as u32)) })
|
||||||
}
|
}
|
||||||
Event::Touch(Touch { phase: TouchPhase::Cancelled, id, ..}) => handler.on_touch(&self.seat, self.time_counter, TouchEvent::Cancel { slot: Some(TouchSlot::new(id as u32)) }),
|
|
||||||
Event::Closed => return Err(GlutinInputError::WindowClosed),
|
Event::Closed => return Err(GlutinInputError::WindowClosed),
|
||||||
_ => {},
|
_ => {}
|
||||||
}
|
}
|
||||||
self.time_counter += 1;
|
self.time_counter += 1;
|
||||||
}
|
}
|
||||||
|
@ -315,14 +349,13 @@ impl InputBackend for GlutinInputBackend
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlutinInputBackend
|
impl GlutinInputBackend {
|
||||||
{
|
fn new(window: Rc<Window>) -> GlutinInputBackend {
|
||||||
fn new(window: Rc<Window>) -> GlutinInputBackend
|
|
||||||
{
|
|
||||||
GlutinInputBackend {
|
GlutinInputBackend {
|
||||||
window: window,
|
window: window,
|
||||||
time_counter: 0,
|
time_counter: 0,
|
||||||
seat: Seat::new(0, SeatCapabilities {
|
seat: Seat::new(0,
|
||||||
|
SeatCapabilities {
|
||||||
pointer: true,
|
pointer: true,
|
||||||
keyboard: true,
|
keyboard: true,
|
||||||
touch: true,
|
touch: true,
|
||||||
|
@ -359,8 +392,7 @@ impl From<GlutinPixelFormat> for PixelFormat {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<GlutinMouseButton> for MouseButton
|
impl From<GlutinMouseButton> for MouseButton {
|
||||||
{
|
|
||||||
fn from(button: GlutinMouseButton) -> MouseButton {
|
fn from(button: GlutinMouseButton) -> MouseButton {
|
||||||
match button {
|
match button {
|
||||||
GlutinMouseButton::Left => MouseButton::Left,
|
GlutinMouseButton::Left => MouseButton::Left,
|
||||||
|
@ -371,8 +403,7 @@ impl From<GlutinMouseButton> for MouseButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ElementState> for KeyState
|
impl From<ElementState> for KeyState {
|
||||||
{
|
|
||||||
fn from(state: ElementState) -> Self {
|
fn from(state: ElementState) -> Self {
|
||||||
match state {
|
match state {
|
||||||
ElementState::Pressed => KeyState::Pressed,
|
ElementState::Pressed => KeyState::Pressed,
|
||||||
|
@ -381,8 +412,7 @@ impl From<ElementState> for KeyState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ElementState> for MouseButtonState
|
impl From<ElementState> for MouseButtonState {
|
||||||
{
|
|
||||||
fn from(state: ElementState) -> Self {
|
fn from(state: ElementState) -> Self {
|
||||||
match state {
|
match state {
|
||||||
ElementState::Pressed => MouseButtonState::Pressed,
|
ElementState::Pressed => MouseButtonState::Pressed,
|
||||||
|
|
|
@ -61,8 +61,7 @@ pub struct PixelFormat {
|
||||||
|
|
||||||
/// Trait that describes objects that have an OpenGl context
|
/// Trait that describes objects that have an OpenGl context
|
||||||
/// and can be used to render upon
|
/// and can be used to render upon
|
||||||
pub trait OpenglGraphicsBackend
|
pub trait OpenglGraphicsBackend {
|
||||||
{
|
|
||||||
/// Swaps buffers at the end of a frame.
|
/// Swaps buffers at the end of a frame.
|
||||||
fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
|
fn swap_buffers(&self) -> Result<(), SwapBuffersError>;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Common traits and types used for software rendering on graphics backends
|
//! Common traits and types used for software rendering on graphics backends
|
||||||
|
|
||||||
use wayland_server::protocol::wl_shm::Format;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use wayland_server::protocol::wl_shm::Format;
|
||||||
|
|
||||||
/// Trait that describes objects providing a software rendering implementation
|
/// Trait that describes objects providing a software rendering implementation
|
||||||
pub trait CpuGraphicsBackend<E: Error> {
|
pub trait CpuGraphicsBackend<E: Error> {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
//! Common traits for input backends to receive input from.
|
//! Common traits for input backends to receive input from.
|
||||||
|
|
||||||
use backend::{SeatInternal, TouchSlotInternal};
|
use backend::{SeatInternal, TouchSlotInternal};
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
@ -12,20 +13,23 @@ use std::error::Error;
|
||||||
///
|
///
|
||||||
/// Seats can be checked for equality and hashed for differentiation.
|
/// Seats can be checked for equality and hashed for differentiation.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct Seat { id: u32, capabilities: SeatCapabilities }
|
pub struct Seat {
|
||||||
|
id: u32,
|
||||||
|
capabilities: SeatCapabilities,
|
||||||
|
}
|
||||||
|
|
||||||
impl SeatInternal for Seat
|
impl SeatInternal for Seat {
|
||||||
{
|
fn new(id: u32, capabilities: SeatCapabilities) -> Seat {
|
||||||
fn new(id: u32, capabilities: SeatCapabilities) -> Seat
|
Seat {
|
||||||
{
|
id: id,
|
||||||
Seat { id: id, capabilities: capabilities }
|
capabilities: capabilities,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Seat {
|
impl Seat {
|
||||||
/// Get the currently capabilities of this `Seat`
|
/// Get the currently capabilities of this `Seat`
|
||||||
pub fn capabilities(&self) -> &SeatCapabilities
|
pub fn capabilities(&self) -> &SeatCapabilities {
|
||||||
{
|
|
||||||
&self.capabilities
|
&self.capabilities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +42,7 @@ pub struct SeatCapabilities {
|
||||||
/// `Seat` has a keyboard
|
/// `Seat` has a keyboard
|
||||||
pub keyboard: bool,
|
pub keyboard: bool,
|
||||||
/// `Seat` has a touchscreen
|
/// `Seat` has a touchscreen
|
||||||
pub touch: bool
|
pub touch: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// State of key on a keyboard. Either pressed or released
|
/// State of key on a keyboard. Either pressed or released
|
||||||
|
@ -74,8 +78,7 @@ pub enum MouseButtonState {
|
||||||
|
|
||||||
/// Axis when scrolling
|
/// Axis when scrolling
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum Axis
|
pub enum Axis {
|
||||||
{
|
|
||||||
/// Vertical axis
|
/// Vertical axis
|
||||||
Vertical,
|
Vertical,
|
||||||
/// Horizonal axis
|
/// Horizonal axis
|
||||||
|
@ -84,8 +87,7 @@ pub enum Axis
|
||||||
|
|
||||||
/// Source of an axis when scrolling
|
/// Source of an axis when scrolling
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum AxisSource
|
pub enum AxisSource {
|
||||||
{
|
|
||||||
/// Finger. Mostly used for trackpads.
|
/// Finger. Mostly used for trackpads.
|
||||||
///
|
///
|
||||||
/// Guarantees that a scroll sequence is terminated with a scroll value of 0.
|
/// Guarantees that a scroll sequence is terminated with a scroll value of 0.
|
||||||
|
@ -122,20 +124,19 @@ pub enum AxisSource
|
||||||
/// fingers on a multi-touch enabled input device. Events should only
|
/// fingers on a multi-touch enabled input device. Events should only
|
||||||
/// be interpreted in the context of other events on the same slot.
|
/// be interpreted in the context of other events on the same slot.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct TouchSlot { id: u32 }
|
pub struct TouchSlot {
|
||||||
|
id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
impl TouchSlotInternal for TouchSlot
|
impl TouchSlotInternal for TouchSlot {
|
||||||
{
|
fn new(id: u32) -> Self {
|
||||||
fn new(id: u32) -> Self
|
|
||||||
{
|
|
||||||
TouchSlot { id: id }
|
TouchSlot { id: id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Touch event
|
/// Touch event
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum TouchEvent
|
pub enum TouchEvent {
|
||||||
{
|
|
||||||
/// The start of an event at a given position (x, y).
|
/// The start of an event at a given position (x, y).
|
||||||
///
|
///
|
||||||
/// If the device has multi-touch capabilities a slot is given.
|
/// If the device has multi-touch capabilities a slot is given.
|
||||||
|
@ -145,7 +146,7 @@ pub enum TouchEvent
|
||||||
/// Absolute x-coordinate of the touch position.
|
/// Absolute x-coordinate of the touch position.
|
||||||
x: f64,
|
x: f64,
|
||||||
/// Absolute y-coordinate of the touch position.
|
/// Absolute y-coordinate of the touch position.
|
||||||
y: f64
|
y: f64,
|
||||||
},
|
},
|
||||||
/// Movement of a touch on the device surface to a given position (x, y).
|
/// Movement of a touch on the device surface to a given position (x, y).
|
||||||
///
|
///
|
||||||
|
@ -156,23 +157,24 @@ pub enum TouchEvent
|
||||||
/// Absolute x-coordinate of the final touch position after the motion.
|
/// Absolute x-coordinate of the final touch position after the motion.
|
||||||
x: f64,
|
x: f64,
|
||||||
/// Absolute y-coordinate of the final touch position after the motion.
|
/// Absolute y-coordinate of the final touch position after the motion.
|
||||||
y: f64 },
|
y: f64,
|
||||||
|
},
|
||||||
/// Stop of an event chain.
|
/// Stop of an event chain.
|
||||||
///
|
///
|
||||||
/// If the device has multi-touch capabilities a slot is given.
|
/// If the device has multi-touch capabilities a slot is given.
|
||||||
Up {
|
Up {
|
||||||
/// `TouchSlot`, if the device has multi-touch capabilities
|
/// `TouchSlot`, if the device has multi-touch capabilities
|
||||||
slot: Option<TouchSlot>
|
slot: Option<TouchSlot>,
|
||||||
},
|
},
|
||||||
/// Cancel of an event chain. All previous events in the chain should be ignored.
|
/// Cancel of an event chain. All previous events in the chain should be ignored.
|
||||||
///
|
///
|
||||||
/// If the device has multi-touch capabilities a slot is given.
|
/// If the device has multi-touch capabilities a slot is given.
|
||||||
Cancel {
|
Cancel {
|
||||||
/// `TouchSlot`, if the device has multi-touch capabilities
|
/// `TouchSlot`, if the device has multi-touch capabilities
|
||||||
slot: Option<TouchSlot>
|
slot: Option<TouchSlot>,
|
||||||
},
|
},
|
||||||
/// Signals the end of a set of touchpoints at one device sample time.
|
/// Signals the end of a set of touchpoints at one device sample time.
|
||||||
Frame
|
Frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait that describes objects providing a source of input events. All input backends
|
/// Trait that describes objects providing a source of input events. All input backends
|
||||||
|
|
Loading…
Reference in New Issue