Skip to content

Commit

Permalink
lib: Use nested imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte authored and vberger committed Oct 7, 2018
1 parent 850ff69 commit a77e29d
Show file tree
Hide file tree
Showing 33 changed files with 349 additions and 283 deletions.
4 changes: 1 addition & 3 deletions build.rs
@@ -1,9 +1,7 @@
extern crate gl_generator;

use gl_generator::{Api, Fallbacks, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::PathBuf;
use std::{env, fs::File, path::PathBuf};

fn main() {
let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
Expand Down
32 changes: 19 additions & 13 deletions src/backend/drm/backend.rs
@@ -1,22 +1,28 @@
use super::error::*;
use super::DevPath;
use backend::graphics::egl::error::Result as EGLResult;
use backend::graphics::egl::native::{Gbm, GbmSurfaceArguments};
use backend::graphics::egl::wayland::{EGLDisplay, EGLWaylandExtensions};
use backend::graphics::egl::{EGLContext, EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError};
use backend::graphics::GraphicsBackend;
use drm::control::{connector, crtc, encoder, framebuffer, Mode};
use drm::control::{Device, ResourceInfo};
use drm::Device as BasicDevice;
use super::{error::*, DevPath};
use backend::graphics::{
egl::{
error::Result as EGLResult,
native::{Gbm, GbmSurfaceArguments},
wayland::{EGLDisplay, EGLWaylandExtensions},
EGLContext, EGLGraphicsBackend, EGLSurface, PixelFormat, SwapBuffersError,
},
GraphicsBackend,
};
use drm::{
control::{connector, crtc, encoder, framebuffer, Device, Mode, ResourceInfo},
Device as BasicDevice,
};
use gbm::{
BufferObject, BufferObjectFlags, Device as GbmDevice, Format as GbmFormat, Surface as GbmSurface,
SurfaceBufferHandle,
};
use image::{ImageBuffer, Rgba};
use nix::libc::c_void;
use std::cell::Cell;
use std::os::unix::io::{AsRawFd, RawFd};
use std::rc::{Rc, Weak};
use std::{
cell::Cell,
os::unix::io::{AsRawFd, RawFd},
rc::{Rc, Weak},
};
use wayland_server::Display;

/// Backend based on a `DrmDevice` and a given crtc
Expand Down
65 changes: 38 additions & 27 deletions src/backend/drm/mod.rs
Expand Up @@ -209,41 +209,52 @@
//! # }
//! ```

use backend::graphics::egl::context::{EGLContext, GlAttributes};
use backend::graphics::egl::error::Result as EGLResult;
use backend::graphics::egl::native::Gbm;
use backend::graphics::egl::wayland::{EGLDisplay, EGLWaylandExtensions};
use backend::graphics::egl::{
context::{EGLContext, GlAttributes},
error::Result as EGLResult,
native::Gbm,
wayland::{EGLDisplay, EGLWaylandExtensions},
};
#[cfg(feature = "backend_session")]
use backend::session::{AsSessionObserver, SessionObserver};
use drm::control::framebuffer;
use drm::control::Device as ControlDevice;
use drm::control::{connector, crtc, encoder, Mode, ResourceInfo};
use drm::result::Error as DrmError;
use drm::Device as BasicDevice;
use drm::{
control::{connector, crtc, encoder, framebuffer, Device as ControlDevice, Mode, ResourceInfo},
result::Error as DrmError,
Device as BasicDevice,
};
use gbm::{BufferObject, Device as GbmDevice};
use nix;
use nix::sys::stat::{self, dev_t, fstat};
use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
use std::io::Error as IoError;
use std::os::unix::io::{AsRawFd, RawFd};
use std::path::PathBuf;
use std::rc::{Rc, Weak};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Once, ONCE_INIT};
use std::time::Duration;

use wayland_server::calloop::generic::{EventedRawFd, Generic};
use wayland_server::calloop::{LoopHandle, Ready, Source};
use wayland_server::Display;
use nix::{
self,
sys::stat::{self, dev_t, fstat},
};
use std::{
cell::RefCell,
collections::HashMap,
hash::{Hash, Hasher},
io::Error as IoError,
os::unix::io::{AsRawFd, RawFd},
path::PathBuf,
rc::{Rc, Weak},
sync::{
atomic::{AtomicBool, Ordering},
Arc, Once, ONCE_INIT,
},
time::Duration,
};

use wayland_server::{
calloop::{
generic::{EventedRawFd, Generic},
LoopHandle, Ready, Source,
},
Display,
};

mod backend;
pub mod error;

pub use self::backend::DrmBackend;
use self::backend::DrmBackendInternal;
use self::error::*;
use self::{backend::DrmBackendInternal, error::*};

static LOAD: Once = ONCE_INIT;

Expand Down
18 changes: 9 additions & 9 deletions src/backend/graphics/egl/context.rs
@@ -1,8 +1,6 @@
//! EGL context related structs

use super::error::*;
use super::native;
use super::{ffi, EGLSurface, PixelFormat};
use super::{error::*, ffi, native, EGLSurface, PixelFormat};
#[cfg(feature = "backend_drm")]
use drm::control::Device as ControlDevice;
#[cfg(feature = "backend_drm")]
Expand All @@ -11,14 +9,16 @@ use drm::Device as BasicDevice;
use gbm::Device as GbmDevice;
use nix::libc::{c_int, c_void};
use slog;
use std::ffi::{CStr, CString};
use std::marker::PhantomData;
use std::mem;
use std::ops::{Deref, DerefMut};
#[cfg(feature = "backend_drm")]
use std::os::unix::io::{AsRawFd, RawFd};
use std::ptr;
use std::rc::Rc;
use std::{
ffi::{CStr, CString},
marker::PhantomData,
mem,
ops::{Deref, DerefMut},
ptr,
rc::Rc,
};

/// EGL context for rendering
pub struct EGLContext<B: native::Backend, N: native::NativeDisplay<B>> {
Expand Down
15 changes: 4 additions & 11 deletions src/backend/graphics/egl/ffi.rs
Expand Up @@ -81,8 +81,7 @@ pub mod egl {
}

mod wayland_storage {
use super::FnPtr;
use super::__gl_imports::raw;
use super::{FnPtr, __gl_imports::raw};
pub static mut BindWaylandDisplayWL: FnPtr = FnPtr {
f: super::missing_fn_panic as *const raw::c_void,
is_loaded: false,
Expand All @@ -99,9 +98,7 @@ pub mod egl {

#[allow(non_snake_case)]
pub mod BindWaylandDisplayWL {
use super::FnPtr;
use super::__gl_imports::raw;
use super::{metaloadfn, wayland_storage};
use super::{FnPtr, __gl_imports::raw, metaloadfn, wayland_storage};

#[inline]
#[allow(dead_code)]
Expand All @@ -123,9 +120,7 @@ pub mod egl {

#[allow(non_snake_case)]
pub mod UnbindWaylandDisplayWL {
use super::FnPtr;
use super::__gl_imports::raw;
use super::{metaloadfn, wayland_storage};
use super::{FnPtr, __gl_imports::raw, metaloadfn, wayland_storage};

#[inline]
#[allow(dead_code)]
Expand All @@ -147,9 +142,7 @@ pub mod egl {

#[allow(non_snake_case)]
pub mod QueryWaylandBufferWL {
use super::FnPtr;
use super::__gl_imports::raw;
use super::{metaloadfn, wayland_storage};
use super::{FnPtr, __gl_imports::raw, metaloadfn, wayland_storage};

#[inline]
#[allow(dead_code)]
Expand Down
3 changes: 1 addition & 2 deletions src/backend/graphics/egl/native.rs
@@ -1,7 +1,6 @@
//! Type safe native types for safe context/surface creation

use super::error::*;
use super::ffi;
use super::{error::*, ffi};
#[cfg(feature = "backend_drm")]
use backend::drm::error::{Error as DrmError, ErrorKind as DrmErrorKind, Result as DrmResult};
#[cfg(feature = "backend_drm")]
Expand Down
11 changes: 5 additions & 6 deletions src/backend/graphics/egl/surface.rs
@@ -1,11 +1,10 @@
//! EGL surface related structs

use super::error::*;
use super::ffi;
use super::native;
use super::{EGLContext, SwapBuffersError};
use std::ops::{Deref, DerefMut};
use std::rc::{Rc, Weak};
use super::{error::*, ffi, native, EGLContext, SwapBuffersError};
use std::{
ops::{Deref, DerefMut},
rc::{Rc, Weak},
};

/// EGL surface of a given egl context for rendering
pub struct EGLSurface<N: native::NativeSurface> {
Expand Down
20 changes: 13 additions & 7 deletions src/backend/graphics/egl/wayland.rs
Expand Up @@ -10,14 +10,20 @@
//! You may then use the resulting `EGLDisplay` to recieve `EGLImages` of an egl-based `WlBuffer`
//! for rendering.

use backend::graphics::egl::error::*;
use backend::graphics::egl::ffi::egl::types::EGLImage;
use backend::graphics::egl::{ffi, native, EGLContext, EglExtensionNotSupportedError};
use backend::graphics::egl::{
error::*,
ffi::{self, egl::types::EGLImage},
native, EGLContext, EglExtensionNotSupportedError,
};
use nix::libc::c_uint;
use std::fmt;
use std::rc::{Rc, Weak};
use wayland_server::protocol::wl_buffer::{self, WlBuffer};
use wayland_server::{Display, Resource};
use std::{
fmt,
rc::{Rc, Weak},
};
use wayland_server::{
protocol::wl_buffer::{self, WlBuffer},
Display, Resource,
};
use wayland_sys::server::wl_display;

/// Error that can occur when accessing an EGL buffer
Expand Down
25 changes: 15 additions & 10 deletions src/backend/graphics/glium.rs
@@ -1,15 +1,20 @@
//! Glium compatibility module

use backend::graphics::egl::error::Result as EGLResult;
use backend::graphics::egl::wayland::{EGLDisplay, EGLWaylandExtensions};
use backend::graphics::egl::{EGLGraphicsBackend, SwapBuffersError};
use glium::backend::{Backend, Context, Facade};
use glium::debug::DebugCallbackBehavior;
use glium::Frame;
use glium::SwapBuffersError as GliumSwapBuffersError;
use std::cell::{Ref, RefCell, RefMut};
use std::os::raw::c_void;
use std::rc::Rc;
use backend::graphics::egl::{
error::Result as EGLResult,
wayland::{EGLDisplay, EGLWaylandExtensions},
EGLGraphicsBackend, SwapBuffersError,
};
use glium::{
backend::{Backend, Context, Facade},
debug::DebugCallbackBehavior,
Frame, SwapBuffersError as GliumSwapBuffersError,
};
use std::{
cell::{Ref, RefCell, RefMut},
os::raw::c_void,
rc::Rc,
};
use wayland_server::Display;

impl From<SwapBuffersError> for GliumSwapBuffersError {
Expand Down
3 changes: 1 addition & 2 deletions src/backend/input.rs
@@ -1,7 +1,6 @@
//! Common traits for input backends to receive input from.

use std::error::Error;
use std::string::ToString;
use std::{error::Error, string::ToString};

/// A seat describes a group of input devices and at least one
/// graphics device belonging together.
Expand Down
27 changes: 15 additions & 12 deletions src/backend/libinput.rs
@@ -1,22 +1,25 @@
//! Implementation of input backend trait for types provided by `libinput`

use backend::input as backend;
use backend::input::Axis;
#[cfg(feature = "backend_session")]
use backend::session::{AsErrno, Session, SessionObserver};
use backend::{input as backend, input::Axis};
use input as libinput;
use input::event;

use std::cell::RefCell;
use std::collections::hash_map::{DefaultHasher, Entry, HashMap};
use std::hash::{Hash, Hasher};
use std::io::Error as IoError;
use std::os::unix::io::RawFd;
use std::path::Path;
use std::rc::Rc;

use wayland_server::calloop::generic::{EventedRawFd, Generic};
use wayland_server::calloop::{LoopHandle, Ready, Source};
use std::{
cell::RefCell,
collections::hash_map::{DefaultHasher, Entry, HashMap},
hash::{Hash, Hasher},
io::Error as IoError,
os::unix::io::RawFd,
path::Path,
rc::Rc,
};

use wayland_server::calloop::{
generic::{EventedRawFd, Generic},
LoopHandle, Ready, Source,
};

// No idea if this is the same across unix platforms
// Lets make this linux exclusive for now, once someone tries to build it for
Expand Down
12 changes: 5 additions & 7 deletions src/backend/session/auto.rs
Expand Up @@ -28,16 +28,14 @@
//! automatically by the `UdevBackend`, if not done manually).
//! ```

use super::direct::{self, direct_session_bind, BoundDirectSession, DirectSession, DirectSessionNotifier};
#[cfg(feature = "backend_session_logind")]
use super::logind::{self, logind_session_bind, BoundLogindSession, LogindSession, LogindSessionNotifier};
use super::{AsErrno, AsSessionObserver, Session, SessionNotifier, SessionObserver};
use super::{
direct::{self, direct_session_bind, BoundDirectSession, DirectSession, DirectSessionNotifier},
AsErrno, AsSessionObserver, Session, SessionNotifier, SessionObserver,
};
use nix::fcntl::OFlag;
use std::cell::RefCell;
use std::io::Error as IoError;
use std::os::unix::io::RawFd;
use std::path::Path;
use std::rc::Rc;
use std::{cell::RefCell, io::Error as IoError, os::unix::io::RawFd, path::Path, rc::Rc};

use wayland_server::calloop::LoopHandle;

Expand Down
26 changes: 16 additions & 10 deletions src/backend/session/dbus/logind.rs
Expand Up @@ -35,18 +35,24 @@ use dbus::{
BusName, BusType, Connection, ConnectionItem, ConnectionItems, Interface, Member, Message, MessageItem,
OwnedFd, Path as DbusPath, Watch, WatchEvent,
};
use nix::fcntl::OFlag;
use nix::sys::stat::{fstat, major, minor, stat};
use std::cell::RefCell;
use std::io::Error as IoError;
use std::os::unix::io::RawFd;
use std::path::Path;
use std::rc::{Rc, Weak};
use std::sync::atomic::{AtomicBool, Ordering};
use nix::{
fcntl::OFlag,
sys::stat::{fstat, major, minor, stat},
};
use std::{
cell::RefCell,
io::Error as IoError,
os::unix::io::RawFd,
path::Path,
rc::{Rc, Weak},
sync::atomic::{AtomicBool, Ordering},
};
use systemd::login;

use wayland_server::calloop::generic::{Event, EventedRawFd, Generic};
use wayland_server::calloop::{LoopHandle, Ready, Source};
use wayland_server::calloop::{
generic::{Event, EventedRawFd, Generic},
LoopHandle, Ready, Source,
};

struct LogindSessionImpl {
conn: RefCell<Connection>,
Expand Down

0 comments on commit a77e29d

Please sign in to comment.