Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Rust 2018 Edition #124

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ authors = ["Victor Berger <victor.berger@m4x.org>", "Drakulix (Victor Brekenfeld
license = "MIT"
description = "Smithay is a library for writing wayland compositors."
repository = "https://github.com/Smithay/smithay"
edition = "2018"

[workspace]
members = [ "anvil" ]
Expand Down
1 change: 1 addition & 0 deletions anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.1"
authors = ["Victor Berger <victor.berger@m4x.org>", "Drakulix (Victor Brekenfeld)"]
license = "MIT"
publish = false
edition = "2018"

[dependencies]
slog = { version = "2.1.1" }
Expand Down
18 changes: 9 additions & 9 deletions anvil/src/glium_drawer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ use smithay::{
egl::{BufferAccessError, EGLImages, Format},
graphics::{gl::GLGraphicsBackend, glium::GliumGraphicsBackend},
},
reexports::wayland_server::{
protocol::{wl_buffer, wl_surface},
Resource,
},
wayland::{
compositor::{roles::Role, SubsurfaceRole, TraversalAction},
data_device::DnDIconRole,
seat::CursorImageRole,
shm::with_buffer_contents as shm_buffer_contents,
},
wayland_server::{
protocol::{wl_buffer, wl_surface},
Resource,
},
};

use shaders;
use shell::{MyCompositorToken, MyWindowMap};
use crate::shaders;
use crate::shell::{MyCompositorToken, MyWindowMap};

#[derive(Copy, Clone)]
struct Vertex {
Expand All @@ -52,7 +52,7 @@ pub struct GliumDrawer<F: GLGraphicsBackend + 'static> {
}

impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
pub fn borrow(&self) -> Ref<F> {
pub fn borrow(&self) -> Ref<'_, F> {
self.display.borrow()
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {
}
Ok(TextureMetadata {
texture: opengl_texture,
fragment: ::shaders::BUFFER_RGBA,
fragment: crate::shaders::BUFFER_RGBA,
y_inverted: images.y_inverted,
dimensions: (images.width, images.height),
images: Some(images), // I guess we need to keep this alive ?
Expand All @@ -205,7 +205,7 @@ impl<F: GLGraphicsBackend + 'static> GliumDrawer<F> {

fn texture_from_shm_buffer(&self, buffer: Resource<wl_buffer::WlBuffer>) -> Result<TextureMetadata, ()> {
match shm_buffer_contents(&buffer, |slice, data| {
::shm_load::load_shm_buffer(data, slice)
crate::shm_load::load_shm_buffer(data, slice)
.map(|(image, kind)| (Texture2d::new(&self.display, image).unwrap(), kind, data))
}) {
Ok(Ok((texture, kind, data))) => Ok(TextureMetadata {
Expand Down
4 changes: 2 additions & 2 deletions anvil/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use smithay::{
self, Event, InputBackend, InputHandler, KeyState, KeyboardKeyEvent, PointerAxisEvent,
PointerButtonEvent, PointerMotionAbsoluteEvent, PointerMotionEvent,
},
reexports::wayland_server::protocol::wl_pointer,
wayland::{
seat::{keysyms as xkb, AxisFrame, KeyboardHandle, Keysym, ModifiersState, PointerHandle},
SERIAL_COUNTER as SCOUNTER,
},
wayland_server::protocol::wl_pointer,
};

use shell::MyWindowMap;
use crate::shell::MyWindowMap;

pub struct AnvilInputHandler {
log: Logger,
Expand Down
8 changes: 3 additions & 5 deletions anvil/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#![warn(rust_2018_idioms)]

#[macro_use]
extern crate glium;
extern crate rand;
#[macro_use]
extern crate slog;
extern crate slog_async;
extern crate slog_term;
#[macro_use(define_roles)]
extern crate smithay;
extern crate xkbcommon;

use slog::Drain;
use smithay::wayland_server::{calloop::EventLoop, Display};
use smithay::reexports::wayland_server::{calloop::EventLoop, Display};

#[macro_use]
mod shaders;
Expand Down
12 changes: 6 additions & 6 deletions anvil/src/shaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ macro_rules! make_program(
($display: expr, $fragment_shader:expr) => {
program!($display,
100 => {
vertex: ::shaders::VERTEX_SHADER,
vertex: crate::shaders::VERTEX_SHADER,
fragment: $fragment_shader,
},
).unwrap()
Expand All @@ -23,11 +23,11 @@ macro_rules! make_program(
macro_rules! opengl_programs(
($display: expr) => {
[
make_program!($display, ::shaders::FRAGMENT_SHADER_RGBA),
make_program!($display, ::shaders::FRAGMENT_SHADER_ABGR),
make_program!($display, ::shaders::FRAGMENT_SHADER_XBGR),
make_program!($display, ::shaders::FRAGMENT_SHADER_BGRA),
make_program!($display, ::shaders::FRAGMENT_SHADER_BGRX),
make_program!($display, crate::shaders::FRAGMENT_SHADER_RGBA),
make_program!($display, crate::shaders::FRAGMENT_SHADER_ABGR),
make_program!($display, crate::shaders::FRAGMENT_SHADER_XBGR),
make_program!($display, crate::shaders::FRAGMENT_SHADER_BGRA),
make_program!($display, crate::shaders::FRAGMENT_SHADER_BGRX),
]
}
);
Expand Down
12 changes: 6 additions & 6 deletions anvil/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::{
use rand;

use smithay::{
reexports::wayland_server::{
protocol::{wl_buffer, wl_callback, wl_shell_surface, wl_surface},
Display, Resource,
},
wayland::{
compositor::{compositor_init, CompositorToken, SurfaceAttributes, SurfaceEvent},
data_device::DnDIconRole,
Expand All @@ -21,13 +25,9 @@ use smithay::{
},
},
},
wayland_server::{
protocol::{wl_buffer, wl_callback, wl_shell_surface, wl_surface},
Display, Resource,
},
};

use window_map::{Kind as SurfaceKind, WindowMap};
use crate::window_map::{Kind as SurfaceKind, WindowMap};

define_roles!(Roles =>
[ XdgSurface, XdgSurfaceRole ]
Expand Down Expand Up @@ -132,7 +132,7 @@ pub fn init_shell(
#[derive(Default)]
pub struct SurfaceData {
pub buffer: Option<Resource<wl_buffer::WlBuffer>>,
pub texture: Option<::glium_drawer::TextureMetadata>,
pub texture: Option<crate::glium_drawer::TextureMetadata>,
}

fn surface_commit(surface: &Resource<wl_surface::WlSurface>, token: CompositorToken<SurfaceData, Roles>) {
Expand Down
14 changes: 7 additions & 7 deletions anvil/src/shm_load.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::borrow::Cow;

use smithay::{wayland::shm::BufferData, wayland_server::protocol::wl_shm::Format};
use smithay::{reexports::wayland_server::protocol::wl_shm::Format, wayland::shm::BufferData};

use glium::texture::{ClientFormat, RawImage2d};

pub fn load_shm_buffer(data: BufferData, pool: &[u8]) -> Result<(RawImage2d<u8>, usize), Format> {
pub fn load_shm_buffer(data: BufferData, pool: &[u8]) -> Result<(RawImage2d<'_, u8>, usize), Format> {
let offset = data.offset as usize;
let width = data.width as usize;
let height = data.height as usize;
Expand All @@ -17,7 +17,7 @@ pub fn load_shm_buffer(data: BufferData, pool: &[u8]) -> Result<(RawImage2d<u8>,
// ensure consistency, the SHM handler of smithay should ensure this
assert!(offset + (height - 1) * stride + width * pixelsize <= pool.len());

let slice: Cow<[u8]> = if stride == width * pixelsize {
let slice: Cow<'_, [u8]> = if stride == width * pixelsize {
// the buffer is cleanly continuous, use as-is
Cow::Borrowed(&pool[offset..(offset + height * width * pixelsize)])
} else {
Expand All @@ -33,10 +33,10 @@ pub fn load_shm_buffer(data: BufferData, pool: &[u8]) -> Result<(RawImage2d<u8>,

// sharders format need to be reversed to account for endianness
let (client_format, fragment) = match data.format {
Format::Argb8888 => (ClientFormat::U8U8U8U8, ::shaders::BUFFER_BGRA),
Format::Xrgb8888 => (ClientFormat::U8U8U8U8, ::shaders::BUFFER_BGRX),
Format::Rgba8888 => (ClientFormat::U8U8U8U8, ::shaders::BUFFER_ABGR),
Format::Rgbx8888 => (ClientFormat::U8U8U8U8, ::shaders::BUFFER_XBGR),
Format::Argb8888 => (ClientFormat::U8U8U8U8, crate::shaders::BUFFER_BGRA),
Format::Xrgb8888 => (ClientFormat::U8U8U8U8, crate::shaders::BUFFER_BGRX),
Format::Rgba8888 => (ClientFormat::U8U8U8U8, crate::shaders::BUFFER_ABGR),
Format::Rgbx8888 => (ClientFormat::U8U8U8U8, crate::shaders::BUFFER_XBGR),
_ => return Err(data.format),
};
Ok((
Expand Down
8 changes: 4 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ use smithay::{
},
};

use glium_drawer::GliumDrawer;
use input_handler::AnvilInputHandler;
use shell::{init_shell, MyWindowMap, Roles, SurfaceData};
use crate::glium_drawer::GliumDrawer;
use crate::input_handler::AnvilInputHandler;
use crate::shell::{init_shell, MyWindowMap, Roles, SurfaceData};

pub struct SessionFd(RawFd);
impl AsRawFd for SessionFd {
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger
/*
* Initialize the udev backend
*/
let context = ::smithay::udev::Context::new().map_err(|_| ())?;
let context = ::smithay::reexports::udev::Context::new().map_err(|_| ())?;
let seat = session.seat();

let primary_gpu = primary_gpu(&context, &seat).unwrap_or_default();
Expand Down
2 changes: 1 addition & 1 deletion anvil/src/window_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use smithay::{
reexports::wayland_server::{protocol::wl_surface, Resource},
utils::Rectangle,
wayland::{
compositor::{roles::Role, CompositorToken, SubsurfaceRole, SurfaceAttributes, TraversalAction},
Expand All @@ -7,7 +8,6 @@ use smithay::{
xdg::{ToplevelSurface, XdgSurfaceRole},
},
},
wayland_server::{protocol::wl_surface, Resource},
};

pub enum Kind<U, R, SD, D> {
Expand Down
8 changes: 4 additions & 4 deletions anvil/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ use std::{

use smithay::{
backend::{egl::EGLGraphicsBackend, graphics::gl::GLGraphicsBackend, input::InputBackend, winit},
reexports::wayland_server::{calloop::EventLoop, protocol::wl_output, Display},
wayland::{
data_device::{default_action_chooser, init_data_device, set_data_device_focus, DataDeviceEvent},
output::{Mode, Output, PhysicalProperties},
seat::{CursorImageStatus, Seat, XkbConfig},
shm::init_shm_global,
},
wayland_server::{calloop::EventLoop, protocol::wl_output, Display},
};

use slog::Logger;

use glium_drawer::GliumDrawer;
use input_handler::AnvilInputHandler;
use shell::init_shell;
use crate::glium_drawer::GliumDrawer;
use crate::input_handler::AnvilInputHandler;
use crate::shell::init_shell;

pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Logger) -> Result<(), ()> {
let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?;
Expand Down
6 changes: 3 additions & 3 deletions examples/raw_drm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate smithay;
#![warn(rust_2018_idioms)]

#[macro_use]
extern crate slog;
extern crate slog_term;

use slog::Drain;
use smithay::{
Expand Down Expand Up @@ -145,7 +145,7 @@ impl DeviceHandler for DrmHandlerImpl {
// now we could render to the mapping via software rendering.
// this example just sets some grey color

for mut x in mapping.as_mut() {
for x in mapping.as_mut() {
*x = 128;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/backend/drm/egl/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! and [`EglSurface`](::backend::drm::egl::EglSurface).
//!

use backend::egl::error as egl;
use crate::backend::egl::error as egl;

error_chain! {
errors {
Expand Down
14 changes: 7 additions & 7 deletions src/backend/drm/egl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use std::rc::Rc;
use wayland_server::Display;

use super::{Device, DeviceHandler, Surface};
use backend::egl::context::GlAttributes;
use backend::egl::error::Result as EGLResult;
use backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use backend::egl::EGLContext;
use crate::backend::egl::context::GlAttributes;
use crate::backend::egl::error::Result as EGLResult;
use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use crate::backend::egl::EGLContext;
#[cfg(feature = "native_lib")]
use backend::egl::{EGLDisplay, EGLGraphicsBackend};
use crate::backend::egl::{EGLDisplay, EGLGraphicsBackend};

pub mod error;
use self::error::*;
Expand Down Expand Up @@ -87,7 +87,7 @@ where
where
L: Into<Option<::slog::Logger>>,
{
let log = ::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_egl"));
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_egl"));

dev.clear_handler();

Expand All @@ -108,7 +108,7 @@ where
D: Device + NativeDisplay<B, Arguments = crtc::Handle> + 'static,
<D as Device>::Surface: NativeSurface,
{
handler: Box<DeviceHandler<Device = EglDevice<B, D>> + 'static>,
handler: Box<dyn DeviceHandler<Device = EglDevice<B, D>> + 'static>,
}

impl<B, D> DeviceHandler for InternalDeviceHandler<B, D>
Expand Down
6 changes: 3 additions & 3 deletions src/backend/drm/egl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use drm::control::crtc;
use std::os::unix::io::RawFd;

use super::EglDevice;
use backend::drm::Device;
use backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use backend::session::{AsSessionObserver, SessionObserver};
use crate::backend::drm::Device;
use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use crate::backend::session::{AsSessionObserver, SessionObserver};

/// [`SessionObserver`](SessionObserver)
/// linked to the [`EglDevice`](EglDevice) it was
Expand Down
12 changes: 6 additions & 6 deletions src/backend/drm/egl/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use nix::libc::c_void;
use std::rc::Rc;

use super::error::*;
use backend::drm::{Device, Surface};
use backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use backend::egl::{EGLContext, EGLSurface};
use crate::backend::drm::{Device, Surface};
use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use crate::backend::egl::{EGLContext, EGLSurface};
#[cfg(feature = "renderer_gl")]
use backend::graphics::gl::GLGraphicsBackend;
use crate::backend::graphics::gl::GLGraphicsBackend;
#[cfg(feature = "renderer_gl")]
use backend::graphics::PixelFormat;
use backend::graphics::{CursorBackend, SwapBuffersError};
use crate::backend::graphics::PixelFormat;
use crate::backend::graphics::{CursorBackend, SwapBuffersError};

/// Egl surface for rendering
pub struct EglSurface<B, D>
Expand Down
10 changes: 5 additions & 5 deletions src/backend/drm/gbm/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//! [`GbmDevice`](GbmDevice) and [`GbmSurface`](GbmSurface).
//!

use backend::drm::{Device, RawDevice};
use backend::egl::error::Result as EglResult;
use backend::egl::ffi;
use backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use backend::graphics::SwapBuffersError;
use crate::backend::drm::{Device, RawDevice};
use crate::backend::egl::error::Result as EglResult;
use crate::backend::egl::ffi;
use crate::backend::egl::native::{Backend, NativeDisplay, NativeSurface};
use crate::backend::graphics::SwapBuffersError;

use super::error::{Error, Result};
use super::{GbmDevice, GbmSurface};
Expand Down
2 changes: 1 addition & 1 deletion src/backend/drm/gbm/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ error_chain! {
}

foreign_links {
FailedToSwap(::backend::graphics::SwapBuffersError) #[doc = "Swapping front buffers failed"];
FailedToSwap(crate::backend::graphics::SwapBuffersError) #[doc = "Swapping front buffers failed"];
}
}
Loading